I'm making a small program that needs a login I'm using SQLite as a database and working with NetBeans ide the first (if, else statement) here is to ensure that the user does not leave the text field or the password field empty and it does not work the second (if, else statement) is to check if the password and username are in the database and its working fine here is my code::
private void btnloginActionPerformed(java.awt.event.ActionEvent evt) {
if(jTextField1.getText()== "" || jPasswordField1.getText()=="")
{JOptionPane.showMessageDialog(this, "the usernmae or bassword filed is empty");}
else {
String sql = "SELECT * from Accounts WHERE User LIKE ? AND pass LIKE ? ; ";
try{
pst = con.prepareStatement(sql);
pst.setString(1, jTextField1.getText());
pst.setString(2, jPasswordField1.getText());
rs = pst.executeQuery();
if (rs.next()){
JOptionPane.showMessageDialog(null,"log in successful");
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new booking().setVisible(true);
dispose();
}
});
}
else
{
JOptionPane.showMessageDialog(this, " wrong username or password ");
}
}
catch (Exception e){
JOptionPane.showMessageDialog(this, "error "+e);
}} ```