dimanche 1 mai 2016

I am not able to insert data to sqlite database in JavaFx

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 (?,?)";
        preparedStatement = connect.prepareStatement(query);
        preparedStatement.setString(1, userNew);
        preparedStatement.setString(2, passNew);
        resultSet = preparedStatement.executeQuery();
            return true;
            return false;
    }catch(Exception e){
        return false;

This is the UserController.Class that calls the UserModel's constructor first and the required @FXML tags

UserModel userModel = new UserModel();

private Label userLbl2;

private TextField UserField;

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");
            userLbl2.setText("Your account has not been created");
    } catch (SQLException e) {
        // TODO Auto-generated catch block

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