dimanche 13 décembre 2015

Trouble in querying table: No such column

This is the log cat :

Caused by: android.database.sqlite.SQLiteException: no such column: uname (code 1): , while compiling: select uname , pass fromaccounts

this is my code in the SqliteDatabase Helper:

public String searchPass(String uname)
{
    db = this.getReadableDatabase();
    String query = "select uname , pass from"+TABLE_NAME;
    Cursor cursor = db.rawQuery(query , null);
    String a, b;
    b = "not found";
    if (cursor.moveToFirst())
    {
        do {
            a = cursor.getString(0);
            b = cursor.getString(1);

            if (a.equals(uname))
            {
                b = cursor.getString(1);
                break;
            }
        }
        while (cursor.moveToNext());
    }
    return b;
}

These are my columns:

     private static final int DATABASE_VERSION = 1;
     private static final String DATABASE_NAME = "echo_all.db";
     private static final String TABLE_NAME = "accounts";
     private static final String COLUMN_ID = "id";
     private static final String COLUMN_FIRST_NAME = "fname";
     private static final String COLUMN_LAST_NAME = "lname";
     private static final String COLUMN_USERNAME = "uname";
     private static final String COLUMN_EMAIL = "email";
     private static final String COLUMN_PASS = "pass";
     SQLiteDatabase db;
     private static final String TABLE_CREATE = "create table accounts (id integer primary key not null ," +
        "fname text not null , lname text not null , uname text not null , email text not null , pass text not null );";

I need help when it codes to solving the log cat error with "select uname , pass from"+TABLE_NAME; It is marking it an error in the log cat. Please help thanks.

Aucun commentaire:

Enregistrer un commentaire