[英]SQLite and Cursor
我的問題是我無法使用 Cursor 從數據庫中檢索數據,並且在所有情況下都會拋出 SQLite 異常
db.execSQL("CREATE TABLE BOOKS ("
+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "Name TEXT, "
+ "Sub_Field TEXT, "
+ "Cover INTEGER, "
+ "Priority INTEGER);");
ContentValues BookValue = new ContentValues();
BookValue.put("Name", "Cisco");
BookValue.put("Sub_Field", "Net");
BookValue.put("Cover", R.drawable.cappuccino );
BookValue.put("Priority", 1);
db.insert("BOOKS", null, BookValue);
主要活動:
try {
SQLiteOpenHelper myDatabase = new myDatabase(this);
db = myDatabase.getWritableDatabase();
myText = (TextView) findViewById(R.id.txt);
cursor = db.query("BOOK", new String[] {"Name", "Sub_Field"}, null,null, null, null,null);
if (cursor != null) {
cursor.moveToFirst();
String name = cursor.getString(0);
myText.setText(name);
}
} catch (SQLiteException e ) {
myText = (TextView) findViewById(R.id.txt);
myText.setText("Try Again, you're soon to achieve your Goal...");
myText.setTextSize(20);
}
在您查詢(選擇)您的表名是“BOOK”,但您正在創建表“BOOKS”並將數據插入“BOOKS”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.