Hi,
I was trying to use the user entered id and password from a logon method and verify if they exist.
It seems that the program is returning false even if the user exists in the database.
There must be some logical error with my Implementation method..
Could you please check what the error could be.
>>>
If the user exists, I would like return true, if not then false.
Here is the method that returns the boolen value:
public boolean verify(int ID, String password){
try{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDri
ver" );
connection = DriverManager.getConnectio
n(
url, username, password );
String sql = "SELECT UST_ID, PASSWORD FROM STUDENT WHERE UST_ID = ? and PASSWORD = ?";
PreparedStatement ps = connection.prepareStatemen
t(sql);
ps.setInt(1, ID);
ps.setString(2, "password");
ps.executeQuery();
ResultSet rs = ps.executeQuery();
if (rs.next())
// valid
return true;
System.out.println("GET LOST FRED");
}
catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
System.exit( 1 ); // terminate program
}
catch ( SQLException sqlex ) {
System.err.println( "Unable to connect" );
sqlex.printStackTrace();
System.exit( 1 ); // terminate program
}
return false; //???????
}
Thanks.
_Esam
Start Free Trial