When a user enter their password I'd like two tables of a database to be queried, one to check that the password is valid and one to check that a user is signed on another system and if these two queries are right then they can proceed.
The code is the following:
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == submit)
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url, user, password;
url ="jdbc
dbc:STUDENT";
user = "MSC030";
password = "bagpuss";
Connection conn =DriverManager.getConnection(url, user, password);
String sta=id.getText();
String query="SELECT PASSWORD FROM MSC030.STAFF WHERE STAFF_NO='"+ sta + "'";
String vquery="SELECT SIGN FROM MSC030.AR WHERE STAFF_NO='"+ sta + "'";
ResultSet theResult;
ResultSet check;
Statement stmt=conn.createStatement();
theResult=stmt.executeQuery(query);
check=stmt.executeQuery(vquery);
while (theResult.next() && check.next()){
String spass=pas.getText();
String p=spass.trim();
String ar;
String valid;
valid=theResult.getString("PASSWORD");
ar=check.getString("SIGN");
String ch= ar.trim();
String v=valid.trim();
if (v.equals(p) && (ch=="Y"))
{Frame frame=new Frame();
frame.setTitle("Password");
Jobs test=new Jobs();
frame.setSize(250,250);
frame.setBackground(Color.lightGray);
frame.add(
test);
frame.setVisible(true);
}
else
{
Frame frame=new Frame();
frame.setTitle("Jobs");
Staff test=new Staff();
frame.setSize(250,250);
frame.setBackground(Color.lightGray);
frame.add(test);
frame.setVisible(true);
}
}
}
catch(SQLException s)
{System.out.print("SQL Error:" +s.toString() + "" + s.getErrorCode() + "" + s.getSQLState());
}
catch(ClassNotFoundException s)
{System.out.print("Class not found");
}
}
The compiler finds no error but when I try it I receive this message:
SQL Error:java.sql.SQLException:ResultSet is closed0null
Could anyone tell me what I'm doing wrong?
Thanks