Part of my application is to bring user account information from dynamic database. When a user entered his username and password, I will search for username in the database and bring all data related to his username. I am using getTwitterAccount for search and My primary key is String “TW_USERNAME”. Here it’s part of database code:
public String[] getTwitterAccount(String username) {
Cursor cursor = db.query(true, TABLE_1, null, TW_USERNAME + "=" + username, null, null, null, null, null);
if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
return null;
}
String[] account = new String[3];
account[0] = cursor.getString(cursor.getColumnIndex(TW_USERNAME));
account[1] = cursor.getString(cursor.getColumnIndex(TW_AUTH_KEY));
account[2] = cursor.getString(cursor.getColumnIndex(TW_AUTH_SECRET_KEY));
return account;
}
I got error in the query. I searched for this problem and they said “Primary key should be integer “_id”. Is there anyway to search in the database by using String not Integer?
try this: TW_USERNAME + “= ‘” + username +”‘” Your input parameter should be in single quotes, if it is String.