因此,我試圖從我的數據庫表中取數據,請你檢查一下,看看你是否可以發現錯誤?Android SQLite創建的數據庫,但無法找到表
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH, null,
SQLiteDatabase.OPEN_READONLY);
Cursor cursor = db.query(TABLE_CLASSES, new String[] { TABLE_C_DAY,
TABLE_C_NAME, TABLE_C_DAY, TABLE_C_LOCATION, TABLE_C_TIMEHR,
TABLE_C_TIMEMIN, TABLE_C_DURATION, TABLE_C_ONETIMEEVENT,
TABLE_C_CTYPE, TABLE_C_OCCURINGWEEK}, TABLE_C_DAY + "=?",
new String[] { String.valueOf(day) }, null, null, null, null);
好吧DB_PATH
是絕對正確的。我試圖關閉數據庫連接,它工作正常,所以數據庫工作正常,並存在。
所有的表列名都是正確的,因爲這些在onCreate中用於創建數據庫,並且工作正常。我使用
db.rawQuery("SELECT * FROM " + TABLE_CLASSES + " WHERE day = ?", new String[] { String.valueOf(day) });
所以,當我使查詢應用程序停止和我在Eclipse中Source code not found
消息也試過。 LogCat說表'類'不存在。
我嘗試手動創建代碼,它的工作。這是來自onCreate(SQLiteDatabase db)的代碼;
String CREATE_DB_WITH_INIT_VALUES =
"CREATE TABLE %1$s (%4$s TEXT);" +
"INSERT INTO %1$s VALUES('Lecture');" +
"INSERT INTO %1$s VALUES('Lab');" +
"INSERT INTO %1$s VALUES('Tutorial');" +
"INSERT INTO %1$s VALUES('Meeting');" +
"INSERT INTO %1$s VALUES('Examples Class');" +
"CREATE TABLE %2$s (%5$s smallint, %6$s varchar(40), %7$s varchar(10), %8$s smallint, %9$s smallint, %10$s smallint, %11$s boolean, %12$s smallint, %13$s smallint);" +
"INSERT INTO %2$s VALUES(1,'COMP12112 Computation',1.1,9,0,60,'False','Lecture',3);" +
"INSERT INTO %2$s VALUES(1,'COMP16212 Java OOP 2',1.1,11,0,45,'False','Lecture',3);" +
"INSERT INTO %2$s VALUES(1,'COMP18111 Distributed Systems','Unix',13,15,60,'False','Lab',3);" +
"INSERT INTO %2$s VALUES(2,'Tutorial','LF13',15,0,60,'False','Tutorial',3);" +
"INSERT INTO %2$s VALUES(2,'COMP14111 AI','LF31',10,30,60,'False','Lab',3);" +
"CREATE TABLE %3$s (%14$s smallint, %15$s smallint, %16$s TEXT, %17$s date);";
CREATE_DB_WITH_INIT_VALUES = String.format(CREATE_DB_WITH_INIT_VALUES, TABLE_CLASS_TYPES,
TABLE_CLASSES, TABLE_DEADLINES, TABLE_CT_TYPE,
TABLE_C_DAY, TABLE_C_NAME, TABLE_C_LOCATION, TABLE_C_TIMEHR, TABLE_C_TIMEMIN, TABLE_C_DURATION,
TABLE_C_ONETIMEEVENT, TABLE_C_CTYPE, TABLE_C_OCCURINGWEEK,
TABLE_D_TIMEHR, TABLE_D_TIMEMIN, TABLE_D_DTEXT, TABLE_D_DDATE
);
db.execSQL(CREATE_DB_WITH_INIT_VALUES);
此代碼不會崩潰,並且一切似乎都很好,但在查詢期間無法找到表。
任何想法是什麼錯?
當你說你試圖手動創建表,你的意思是從一個cmd提示? – 2013-02-26 20:49:18
通過SQLite數據庫瀏覽器,我複製CREATE_DB_WITH_INIT_VALUES格式化後,它工作正常。 – 2013-02-26 20:52:39