I have this on my DBHelper
public Cursor selectUser(String username){
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery("SELECT * FROM user_tbl WHERE username = '" +
username+"'", null);
return res;
}
And i also have this try-catch block on my Activity.
DBHelper mydb;
Cursor res;
user = LoginActivity.usernamee;
try{
res = mydb.selectUser(user);
if(res.getCount() > 0){
String fullnamee = res.getString(res.getColumnIndex(DBHelper.USER_NAME));
fullname.setText(fullnamee);
fullname.setFocusable(false);
fullname.setClickable(false);
}
}catch(Exception e){
System.out.println("Error retrieving database record.");
}
However, I am getting the catch exception. What I am trying to do is that, I would like to check my database where username is equal to LoginActivity.usernamee. Then display the full name of the user from my database table to my Android text view.
I would like to ask for assistance. Thank you!
DBHelperInstead of printing a generic error in yourcatch, you should get the error message from the exception. It'll help you debug any problems.