watch the video for the whole procedure and designing part:
write the following code inside the class:
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
int attempt =1;
Write the following code inside the listening event of button:
write the following code inside the class:
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
int attempt =1;
Write the following code inside the listening event of button:
String sql = "select * from mysqllimitnew where username = ? and password=?";
if(attempt<4){
try{
con = DriverManager.getConnection("jdbc:mysql://localhost/mysqllimitnew", "root", "");
pst = con.prepareStatement(sql);
pst.setString(1, txtuser.getText());
pst.setString(2, txtpass.getText());
rs=pst.executeQuery();
if(rs.next()){
JOptionPane.showMessageDialog(null,"username and password matched"+attempt);
}else
{
JOptionPane.showMessageDialog(null, "error"+attempt);}
}
catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);}
}
else if(attempt!=4){
JOptionPane.showMessageDialog(null,"try once again"+attempt);
}
else{
JOptionPane.showMessageDialog(null,"exceed"+attempt);
txtuser.setEnabled(false);
txtpass.setEditable(false);
}
if(attempt==5){
this.dispose();
}
attempt++;
No comments:
Post a Comment