private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String user= new String(jTextField1.getText());
String pass= new String(jPasswordField1.getPassword());
if(a<4)
{
Connection con = null;
String driver = "oracle.jdbc.driver.OracleDriver";
String user1 = "system";
String pass1 = "manager";
try{
Class.forName(driver);
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/test",user1,pass1);
Statement s=con.createStatement();
ResultSet password=s.executeQuery("Select pass from login where username="+user);
s.close();
con.close();
if(pass.contentEquals(password.getString(1)))
{
a=0;
JOptionPane.showMessageDialog(rootPane, "Access Granted");
ResultSet access=s.executeQuery("Select access_power from login where username="+user);
access_power=access.getString(1);
new Exam_Season().setVisible(true);
this.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(rootPane, "Access Denied.");
a++;
}
}
catch(Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(rootPane, "Connection not successful.");
}
}
else
{
JOptionPane.showMessageDialog(rootPane, "Too many attempts.");
System.exit(0);
}
} |