private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String query;
boolean login = false;
String username = jTextField1.getText();
String password = jTextField2.getText();
try{
query = "SELECT (cUsername AND cPassword) FROM Customer WHERE cUsername = '"+username+"' AND cPassword = '"+password+"'";
pst = conn.prepareStatement(query);
pst.setString(1, username);
pst.setString(2, password);
pst.executeQuery();
String userCheck = rs.getString(1);
String passCheck = rs.getString(2);
if((userCheck.equals(username)) && (passCheck.equals(password)))
{
login = true;
System.out.println("It actually works?!");
}
else
{
login = false;
System.out.println("Psyche, that's the wrong number!");
}
}
catch(Exception e){
System.out.println(e);
}
System.exit(0);
}
I'm currently having difficulty implementing a login system in my code. I'm trying to retrieve the text from username and password jTextFields and then query them to the database but it's not working. At the moment I'm getting
java.lang.ArrayIndexOutOfBoundsException: 0
and I unfortunately have no idea why. Any help would be GREATLY appreciated.
Aucun commentaire:
Enregistrer un commentaire