2017-01-18 60 views
-1

我試過這個查詢,並且遊標一直返回NULL,在表「members」存在1條記錄,謝謝。遊標總是返回空 - SQLite

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; 

} 
+0

寫入= dbhelper.getWritableDatabase(); –

+3

'rawQuery()'不會返回null。請更詳細地解釋你的問題。 – laalto

回答

1

這是工作代碼。比較和嘗試。根據需要變化的東西

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")); 
     } 
    } 
} 
+0

謝謝你的幫助,我沒有「openDatabase」 –