Yasir Yasir - 1 month ago 8
Java Question

Query returing no results codename one

Query showing no results and not giving any error .control not entering inside the if block help me out that where is the mistake i am doing ?
i have tried many ways to get the result but all in vain. When i tried the following before the if statement

int column=cur.getColumnCount();
Row row=cur.getRow();
row.getString(0);


then i got the resultset closed exception

Database db=null;
Cursor cur=null;
System.out.print("Printing from accounts class "+Email+Password);
String [] param={Email,Password};
System.out.print(param[0]+param[1]);

try{
db=Display.getInstance().openOrCreate("UserAccountsDB.db");
cur= db.executeQuery("select * from APPUserInfo WHERE Email=? AND Password=?",(String [])param);
int columns=cur.getColumnCount();
if(columns > 0) {

boolean next = cur.next();
while(next) {
Row currentRow = cur.getRow();
String LoggedUserName=currentRow.getString(0);
String LoggedUserPassword=currentRow.getString(1);
System.out.println(LoggedUserName);
next = cur.next();
}

}
}catch(IOException ex)
{
Util.cleanup(db);
Util.cleanup(cur);
Log.e(ex);
}

finally{
Util.cleanup(db);
Util.cleanup(cur);

}

Answer

As @jobin said in the comments the cursor to the result appears before the first entry so until you invoke next() for the first time you don't have access to the data.

It seems that the table is empty which means there is no user in the DB matching email/password. Try removing the email/password clause to get a list of all the users to verify.