String sql = "select * from users where first_name=? and password=?";
// String sql="select * from Modules where username=? and password=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, txt_username.getText());
pst.setString(2, txt_password.getText());
rs= pst.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Username and Password are correct");
Main s=new Main();
s.setVisible(true);
}else{
JOptionPane.showMessageDialog(null, "Username and Password are not correct");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
in the main class
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
/** Creates new form Login */
public Login() {
initComponents();
conn = javaconnect.ConnecrDB();
}
// String sql="select * from Modules where username=? and password=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, txt_username.getText());
pst.setString(2, txt_password.getText());
rs= pst.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Username and Password are correct");
Main s=new Main();
s.setVisible(true);
}else{
JOptionPane.showMessageDialog(null, "Username and Password are not correct");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
in the main class
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
/** Creates new form Login */
public Login() {
initComponents();
conn = javaconnect.ConnecrDB();
}