Carlos Mina Toro
Carlos Mina Toro

Reputation: 11

Cursor always returns null - SQLite

I tried this query and the cursor alway return to NULL, in the table "members" exist 1 record, Thank you.

    sql = "SELECT nick, pass FROM miembros LIMIT 1";

    cursor = write.rawQuery(sql, null);
    if (cursor != null){
        if(cursor.moveToFirst()) {
             nickDB = cursor.getString(0);
             passDB = cursor.getString(1);
             resp[0] = nickDB;
             resp[1] = passDB;
        }

        // Cierra el cursor
        if(!cursor.isClosed()) cursor.close();
    }else{
        Log.e("CURSOR","CURSOR NULL");
    }
    return resp;

}

Upvotes: 0

Views: 1175

Answers (1)

John Bravado
John Bravado

Reputation: 137

this is working code. compare and try. Change stuff as needed

public void getItem() {
    String selectQuery;
    SQLiteDatabase db;
    String myPath = DATABASE_PATH + DATABASE_NAME;

    db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    selectQuery = "SELECT * FROM TABLE";
    Cursor cursor = db.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        cursor.getInt(cursor.getColumnIndex("id"));

        while (cursor.moveToNext()) {
            cursor.getInt(cursor.getColumnIndex("id"));
        }
    }
}

Upvotes: 2

Related Questions