I am confused by the two questions on the title. What function do you recommend me to use in the following controller class that avoids blank entries in SignUp and makes it impossible to log in with null or "" values without passing authentication? I examined different ways but it either didn't work at all or gave some error. The application works well otherwise. I use an online Mysql and it works well.
@FXML
void fcnBtnSignUp(ActionEvent event) {
try {
conn = dbConnection.connect();
String sql = "insert into tblSignUp (FULL_NAME, GENDER, EMAIL, PASSWORD, RE_PASSWORD) values (?,?,?,?,?)";
pst= conn.prepareStatement(sql);
pst.setString(1, txtFullName.getText());
pst.setString(2, txtGender.getText());
pst.setString(3, txtEmail.getText());
pst.setString(4, txtPassword.getText());
pst.setString(5, txtRePassword.getText());
pst.execute();
txtFullName.setText("");
txtGender.setText("");
txtEmail.setText("");
txtPassword.setText("");
txtRePassword.setText("");
Parent root;
try {
Stage stage = (Stage) btnSignUp.getScene().getWindow();
// do what you have to do
stage.close();
root = FXMLLoader.load(getClass().getResource("SignUpSuccess.fxml"));
Scene s = new Scene(root);
Stage ss = new Stage();
ss.setScene(s);
ss.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (SQLException ex) {
Logger.getLogger(SampleController.class.getName()) . log(Level.SEVERE, null,ex);
}
}
@FXML
void fcnBtnLogin(ActionEvent event) {
String a ="";
try {
conn = dbConnection.connect();
String sql = "Select * from tblSignUp where EMAIL=? AND PASSWORD=?";
pst =conn.prepareStatement(sql);
pst.setString(1, txtLoginEmail.getText());
pst.setString(2, txtLoginPassword.getText());
ResultSet rs = pst.executeQuery();
if(rs.next() == true) {
try {
Stage stage = (Stage) btnLogin.getScene().getWindow();
// do what you have to do
stage.close();
Parent root = FXMLLoader.load(getClass().getResource("ReadingMain.fxml"));
Scene s = new Scene(root);
Stage ss = new Stage();
ss.setScene(s);
ss.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
System.out.println("Login Unsuccessful! Incorrect Username or Password");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}