Hi ,
For the below mentioned code I am getting the invalid cursor state when the query does not return any result from the database.Please let me know how to tackle this situation so that invalid cursor state can be handled
private
String queryLogin;
private String dbUsername;
private String dbPassword;
Connection connection=new ForumConnection().getConnection();
ResultSet resultset=null;
/*
** Writting and executing query for getting usernames and respective password from Login table
*/
queryLogin="select * from Login where username='"+username+"';";
try {
Statement statement=connection.createStatement();
resultset=statement.executeQuery(queryLogin);
resultset.next();
if(resultset!=null){
/* Here the Invalid cursor state exception is thrown */
dbUsername=resultset.getString("Username");
dbPassword=resultset.getString("Password");
}
} catch (SQLException e) {
System.out.println(" Query problem for Login--"+e);
}
if(dbUsername.equals(username) && dbPassword.equals(password) ){
return true;
}
else{
return false;
}
Basically the above code takes the username and password as input string and checks itin the database.If it doesn't exists then it return false.
Regards,