Hello guys i want to make a validation for username and password from my phpmyadmin database using netbeans Jform
here is my code
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String a = username.getText();
String b = password.getText();
try {
//configDB is my connnection file to mysql
java.sql.Connection conn = (Connection) config.configDB();
String username = "select username from akun where username='" + a + "';";
String password = "select password from akun where password='" + b + "';";
java.sql.PreparedStatement us = conn.prepareStatement(username);
java.sql.PreparedStatement pw = conn.prepareStatement(password);
us.execute();
pw.execute();
if (a.equals(username.toString()) && b.equals(password.toString())) {
JOptionPane.showMessageDialog(this, "Benar");
} else {
JOptionPane.showMessageDialog(this, "Username or Password is incorrect");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
} // TODO add your handling code here:
}
2
Answers
Try this.
}
You need to make sure your resources are closed and use the
PreparedStatement
properly: