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 valueCodePudding user response: