Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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 如果(rs.next())始终不工作,请转到其他_Java_Mysql_Oop - Fatal编程技术网

Java 如果(rs.next())始终不工作,请转到其他

Java 如果(rs.next())始终不工作,请转到其他,java,mysql,oop,Java,Mysql,Oop,我使用用户登录、管理员登录等方式在exame系统上工作。 当我检查输入的用户名是否正确时(例如) 如果它已经在数据库中,则不会返回 然后再次创建它 try{ // Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/big_project_3","root",""); //i

我使用用户登录、管理员登录等方式在exame系统上工作。 当我检查输入的用户名是否正确时(例如) 如果它已经在数据库中,则不会返回 然后再次创建它

try{
  //  Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/big_project_3","root","");
    //imporrrrrrrrrrrrrrrrrrrrrrrtant
    String selectquery = "select count(*)from uesrs where username='" + username + "'and password='" + password + "'";
    Statement stat=con.createStatement();
    System.out.println(selectquery);
    ResultSet rs=stat.executeQuery(selectquery);
    System.out.println(rs.next());
    if(rs.next()==true){
        infoMessage("Already registered ","Welcom");
    }
    else{
        String insertQuery = "insert into uesrs values(null,'" + username_new_student.getText() + "','" + password_new_student.getText() + "','" + First_name_new_student.getText()+"')";

        stat.executeUpdate(insertQuery);
        infoMessage("info is inserted ","Alert!!!!!");
        dispose();
        user_login ul=new user_login();
        ul.setLocationRelativeTo(null);
        ul.setVisible(true);
    }
}
catch (Exception ex) {
    System.out.println(ex);
}

调用
rs.next()
inside
System.out.println()
后,指针将向前移动。然后,当您调用
rs.next()
inside
if
条件时,将不会显示更多结果

try{
  //  Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/big_project_3","root","");
    //imporrrrrrrrrrrrrrrrrrrrrrrtant
    String selectquery="select count(*)from uesrs where username='"+username+"'and password='"+password+"'";
    Statement stat=con.createStatement();
    System.out.println(selectquery);
    ResultSet rs=stat.executeQuery(selectquery);

    if(rs.next() ){
        infoMessage("Already registered ","Welcom");
    }
    else{
        String insertQuery="insert into uesrs values(null,'"+username_new_student.getText()+"','"+password_new_student.getText()+"','"+First_name_new_student.getText()+"')";

     stat.executeUpdate(insertQuery);
     infoMessage("info is inserted ","Alert!!!!!");
    dispose();
    user_login ul=new user_login();
    ul.setLocationRelativeTo(null);
    ul.setVisible(true);


    }

}

catch (Exception ex) {
    System.out.println(ex);
}

看起来您的SQL中可能有输入错误。from uesrs可能应该说“from users”
System.out.println(rs.next())-你认为这是在做什么?我在和他一起学习这个教程,这很有效!!!但在rs.next上调用println会推动事情向前发展。尝试注释。尝试选择*而不是选择计数(*)。选择count将始终返回一个带有数字的1条记录集,即使没有匹配的记录集(返回一个带有数字0的1条记录集),请参阅Ahmad Assaf在上面的评论,即当他执行您在这里看到的操作时,它仍然不起作用。这当然是个问题,但不是唯一的问题。