我有一個頁面,可以從數據庫 檢索用戶數據,但經過一整天的嘗試,我只能夠獲取表列名稱,而不是內部的值。從數據庫獲取數據Android
這是我的代碼來創建數據庫
public static final String LASTLOGIN = "lastuser";
public static final String USER_ID = "suser_id";
public static final String USER_NAME = "suser_name";
public static final String USER_PASSWORD = "spassword";
public static final String PRIME_ID = "id";
private static final String TABLE_USER =
"create table "+ LASTLOGIN+" ("
+PRIME_ID+" integer primary key autoincrement, "
+ USER_ID + " text, "
+ USER_NAME +" text, "
+USER_PASSWORD+" text); ";
這裏是函數實現獲取用戶數據
public Cursor getuser()
{
String[] columns = new String[]{PRIME_ID, USER_NAME, USER_PASSWORD};
Cursor cursor = sqLiteDatabase.query(
LASTLOGIN, columns, null, null, null, null, PRIME_ID +" DESC");
Log.d("TAG", columns[1]);
return cursor;
}
,這裏是我的代碼來顯示結果
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToWrite();
cursor = mySQLiteAdapter.getuser();
String[] resultvalue = new String{
SQLiteAdapter.PRIME_ID,SQLiteAdapter.USER_NAME, SQLiteAdapter.USER_PASSWORD};
Toast.makeText(this, resultvalue[0]+resultvalue[1], Toast.LENGTH_LONG).show();
和敬酒結果只顯示列名而不顯示裏面的值,有沒有我犯的錯誤?我想將限制設置爲1,但是在哪裏設置?
感謝您的幫助
謝謝!它的作品〜 只有「cursor.getInteger」應該改爲「cursor.getInt」 – Sunny