Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MySQLConnection-在“的authenticateUser”上出错;此行有多个标记”;_Java_Mysql_Eclipse_Gwt - Fatal编程技术网

Java MySQLConnection-在“的authenticateUser”上出错;此行有多个标记”;

Java MySQLConnection-在“的authenticateUser”上出错;此行有多个标记”;,java,mysql,eclipse,gwt,Java,Mysql,Eclipse,Gwt,我试图在Eclipse中创建我的第一个MySQLConnection,但在authenticateUser上出现了一个错误,即“此行有多个标记” -返回类型与不兼容 DBConnection.authenticateUser(字符串,字符串)” 我理解这意味着“有不止一个错误…但我无法解决问题…” 我用它作为我的向导 这是我的代码: AwardTracker.gwt.xml <module> <inherits name="com.google.gwt.user.User"/

我试图在Eclipse中创建我的第一个MySQLConnection,但在authenticateUser上出现了一个错误,即“此行有多个标记” -返回类型与不兼容 DBConnection.authenticateUser(字符串,字符串)”

我理解这意味着“有不止一个错误…但我无法解决问题…”

我用它作为我的向导

这是我的代码:

AwardTracker.gwt.xml

<module>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.user.theme.standard.Standard"/>
<entry-point class="org.AwardTracker.client.AwardTracker"/>

<!--  servelet context - path is arbitrary, but must match up with the rpc init inside java class -->
<!--  Tomcat will listen for this from the server and waits for rpc request in this context -->
<servelet class="org.AwardTracker.server.MySQLConnection" 
    path="/MySQLConnection" />
    <inherits name="com.google.gwt.user.theme.standard.Standard"/>
    <inherits name="com.google.gwt.user.theme.chrome.Chrome"/>
    <inherits name="com.google.gwt.user.theme.dark.Dark"/>
任何帮助都将不胜感激

问候,

格林

嗨,本文克

谢谢你的帮助。只是为了说明这些教程并不完美。我做了此更改,现在在authenticateUser中出现错误:

while (result.next()) {
user = new User(result.getString(1), result.getString(2));
}
“构造函数用户(字符串,字符串)未定义”

谢谢

格林

嗨,贝夫克

非常感谢你的帮助。我认为缺少了一些“}”,所以我修改如下

另外,除非在异常处理程序中执行某些操作,否则说“User User=null;//必需” “。我的印象是,我们试图找出用户是否在表中,如果不在表中,则返回异常(即验证用户名和密码)。因此,返回需要确认,因此我们正在使用exveption处理程序进行处理。我显然错过了一些东西;那么,我们如何知道用户已成功登录

此外,Eclipse似乎没有关于包的混合情况的问题,因为我正在分阶段进行这项工作,并且所有人都在努力添加它

问候,

格林


您已经定义了该方法

public int authenticateUser(String user, String pass) {
public User authenticateUser(String userName, String pass) {
    User user = null; // necessary unless you do something in the exception handler
    ResultSet result = null;
    PreparedStatement ps = null;
    try {
      ps = conn.prepareStatement(
          "select readonly * from users where username = \"" + userName  + "\" AND " + "password = \"" + pass + "\"");
      result = ps.executeQuery();
      while (result.next()) {
         user = new User(result.getString(1), result.getString(2));
      }
    } catch (SQLException sqle) {
      //do stuff on fail
    }finally{
        if (result != null) {
            try {
                result.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
        }
    }
return user;
然而,您返回的对象是

User user;
阅读本教程时,您似乎应该声明该方法

public int authenticateUser(String user, String pass) {
public User authenticateUser(String userName, String pass) {
    User user = null; // necessary unless you do something in the exception handler
    ResultSet result = null;
    PreparedStatement ps = null;
    try {
      ps = conn.prepareStatement(
          "select readonly * from users where username = \"" + userName  + "\" AND " + "password = \"" + pass + "\"");
      result = ps.executeQuery();
      while (result.next()) {
         user = new User(result.getString(1), result.getString(2));
      }
    } catch (SQLException sqle) {
      //do stuff on fail
    }finally{
        if (result != null) {
            try {
                result.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
        }
    }
return user;

//永远不要捕获这样的异常
。。。除非你刚刚抓住它并丢弃了它。我认为您的意思是不要使用try/catch块,让异常从方法中传播出去。此外,GWT.xml文件中的GWT servlet标记是老派的,如果您可以切换到最新的GWT 2.5和基于annotation/web.xml的方法。您好,SSR,您是否能够为我指出应该如何执行该操作的示例方向?我们将不胜感激。Regatds,GlynHi BenvynQ,谢谢你的帮助。只是为了说明这些教程并不完美。我做了这个更改,现在我在authenticateUser:while(result.next()){user=new user(result.getString(1),result.getString(2));}中得到了一个错误“构造函数用户(String,String)未定义”。谢谢,GlynI已经更新了方法,但出现了一些错误。我还注意到您的包名是混合大小写的。我不知道这是否会混淆eclipse,不应该,但你永远不会知道;非常感谢,格林。