SQL是
INSERT INTO "quotes" VALUES(1,1,1,'This is a quote','This is a quote in german','By Me','jackson',1,1,1305587611,'0','Thriller');
我正在使用 db.execSQL 在从文本文件读取后执行这一行。
InputStream is = myContext.getResources().openRawResource(R.raw.quotesinsert);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String readLine = null;
db.execSQL(QUOTE_DB_CREATE);
while ((readLine = br.readLine()) != null) {
db.execSQL(readLine);
}
这适用于所有其他版本的 Android,但在 ICS(4.0.4) 上崩溃
01-14 02:07:46.271: E/AndroidRuntime(1802): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foo.quotesapp/com.foo.quotesapp.QuoteList}: android.database.sqlite.SQLiteException: near "?INSERT": syntax error
我已经在独立的 SQLite 程序中尝试了创建表的 SQL 和这个插入,它们工作正常,这里会发生什么?
最佳答案
您的文本文件以 UTF-8 编码,并且是使用插入 byte order mark 的程序创建的在一开始。
Java/Android 运行时在读取文件时不会删除这个字符;你必须自己做。
(此行为是故意的;请参阅 UTF-8 encoding does not recognize initial BOM 和 UTF-8 decoder handling of byte-order mark has changed。)
关于android - 在 ICS(4.0.4) 中出现 SQLite 语法错误但在其他版本上工作正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14350195/