samedi 26 décembre 2015

No such table in SQLite

No idea what's wrong with my code. I'm trying to compare the user input password and the password in SQLite, but I get android.database.sqlite.SQLiteException: no such table: User (code 1): , while compiling: SELECT * FROM User WHERE Name1 =? error. I'm sure I have table user since data can be inserted. Code below show the get password code.

 public String getSinlgeEntry(String userName)
    {
        Cursor cursor=database.query(MyDatabaseHelper.TABLE_USER, null, "Name1 =?", new String[]{userName}, null, null, null);
        if(cursor.getCount()<1) // UserName Not Exist
        {
            cursor.close();
            return "NOT EXIST";
        }
        cursor.moveToFirst();
        String password= cursor.getString(cursor.getColumnIndex(MyDatabaseHelper.Password));
        cursor.close();
        return password;
    }

MyDatabaseHelper

public static final String TABLE_USER="User";
public static final String id="id";
public static final String Name1="Name1";
public static final String Password="Password";



public void onCreate(SQLiteDatabase db)
{ 
db.execSQL("create table " + TABLE_USER + " ( " + id + " INTEGER PRIMARY KEY ,Name1 TEXT,Password TEXT)");
}

Aucun commentaire:

Enregistrer un commentaire