Home > Back-end >  PreparedStatement=connection. PrepareStatement (SQL); To run an error
PreparedStatement=connection. PrepareStatement (SQL); To run an error

Time:09-21

Public class UserDao {
The Connection Connection=null;
PreparedStatement PreparedStatement=null;
Public User login (String name, String password) {
User user=null;
The ResultSet ResultSet;

Try {
The connection=DBUtils. GetConnection ();
String SQL="select * from the user where the user. Users. The name=? And the user. Users. Password=?" ;
PreparedStatement=connection. PrepareStatement (SQL);
PreparedStatement. SetString (1, name);
PreparedStatement. SetString (2, password);
The resultSet=preparedStatement. ExecuteQuery ();
If (a resultSet. Next ()) {
User=new user ();
User. Elegantly-named setName (resultSet. Get string (" name "));
User. SetPassword (resultSet. Get string (" password "));
System. The out. Println (" login success ");
} else {
System. The out. Println (" the user name or password error ");
}
} the catch (SQLException e) {
e.printStackTrace();
}

return user;
}
Public Boolean addUser (User User) {

Try {
The connection=DBUtils. GetConnection ();
String SQL="insert into user. Users (name, password) values (?,?,?,?,? ,?) ";
PreparedStatement=connection. PrepareStatement (SQL);
PreparedStatement. SetString (1, user getName ());
PreparedStatement. SetString (2, user. GetPassword ());
If (a preparedStatement. ExecuteUpdate ()!=0) {
System. The out. Println (" to create a new user success ");
return true;
}

} the catch (SQLException e) {
e.printStackTrace();
}

return false;
}
}
Small white for help, run to a preparedStatement=connection. The prepareStatement (SQL); Error is at 500
really don't know how to change, consult bosses

CodePudding user response:

Your name and password have value

CodePudding user response:

reference 1st floor chaimhao response:
your name and the password is there any value

Just changed, the assignment also not line, can't do the

CodePudding user response:

UserDao 23 limits pointer

CodePudding user response:

Forget you this kind of writing should be how to write but is first put a preparedStatement=connection. The prepareStatement (SQL); Again the set value

CodePudding user response:

refer to the second floor qq_41421053 response:
Quote: refer to 1st floor chaimhao response:
your name and the password is there any value

Just changed, the assignment also not line, can't do the


Should be the SQL, the query is null, the SQL look on the database to perform as a result,

CodePudding user response:

The connection==null

CodePudding user response:

The debug knew in 23 a breakpoint and then can see which variable is empty and then the next question
  • Related