This is the UserModel.Class with insert function
public boolean isInsert(String userNew, String passNew) throws SQLException{
PreparedStatement preparedStatement=null;
ResultSet resultSet=null;
String query = "INSERT INTO employee (username, password) VALUES (?,?)";
try{
preparedStatement = connect.prepareStatement(query);
preparedStatement.setString(1, userNew);
preparedStatement.setString(2, passNew);
resultSet = preparedStatement.executeQuery();
if(resultSet.next()){
return true;
}else{
return false;
}
}catch(Exception e){
return false;
}finally{
preparedStatement.close();
resultSet.close();
}
}
This is the UserController.Class that calls the UserModel's constructor first and the required @FXML tags
UserModel userModel = new UserModel();
@FXML
private Label userLbl2;
@FXML
private TextField UserField;
@FXML
private PasswordField PassField;
And then an ActionEvent SignUp takes the userModel Object and calls the above mentioned isInsert function
public void SignUp(ActionEvent event){
try {
if(userModel.isInsert(UserField.getText(), PassField.getText())){
userLbl2.setText("Your account has been created");
}else{
userLbl2.setText("Your account has not been created");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
And below is the last three lines of the error-
Caused by: java.lang.NullPointerException
at application.UserModel.isInsert(UserModel.java:34)
at application.UserController.SignUp(UserController.java:65)
... 56 more
Aucun commentaire:
Enregistrer un commentaire