mercredi 22 avril 2015

getting value from sqltable into string

I need to fetch the data from the database and then i need to compare it with other string i am not able to assign the value to an string

I need to fetch the 5555 and store it into a string or an integer. How could I do it?

SQLiteDatabase db = openOrCreateDatabase("db_name", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS DB_NAME(ID INTEGER(1),PASS INTEGER(4));");
db.rawQuery("INSERT INTO DB_NAME VALUES(1,5555);",null);
Cursor v= db.rawQuery("SELECT PASS FROM DB_NAME WHERE ID=1;",null);
String xyz;
if(v != null && v.moveToFirst()) {
xyz= v.getString(v.getColumnIndex("pass"));
t1.setText(xyz);
}
v.close();
db.close();

Now it's showing the following error

android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

Aucun commentaire:

Enregistrer un commentaire