附近&QUOT SQLite的语法错误; CREATE TABLE" [英] SQLite syntax error near "CREATE TABLE"
问题描述
下面是我的code:
String CREATE_DATABASE = "CREATE TABLE " + TABLE_NAME + "(" +
KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
"title TEXT, "+
"author TEXT, "+
"state TEXT);";
db.execSQL(CREATE_DATABASE);
在LogCat中表示:12-11 23:43:50.553:E / AndroidRuntime(3706):android.database.sqlite.SQLiteException:近CREATE TABLE:语法错误(code 1),在编译:CREATE TABLE PapersTable(_id INTEGER PRIMARY KEY AUTOINCREMENT,标题文本,作者文字,状态TEXT);
The LogCat says : 12-11 23:43:50.553: E/AndroidRuntime(3706): android.database.sqlite.SQLiteException: near "CREATE TABLE": syntax error (code 1): , while compiling: CREATE TABLE PapersTable(_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, author TEXT, state TEXT);
推荐答案
的 CREATE TABLE
语法都是正确的,你已经张贴了。
The CREATE TABLE
syntax is all right as you've posted it.
我怀疑之间有一个不间断空格(ASCII 0XA0)创建
和 TABLE
。与常规的空格(ASCII为0x20)替换它。这可以解释您发布的语法错误:解析器治疗 CREATE TABLE
作为一个单一的未知的令牌,而不是两个单独的已知的标记创建
和 TABLE
。
I suspect there's a non-breaking space (ASCII 0xA0) between CREATE
and TABLE
. Replace it with the regular space (ASCII 0x20). That would explain the syntax error you posted: parser is treating CREATE TABLE
as a single unknown token and not as two separate known tokens CREATE
and TABLE
.
什么是绝对错误的是,你叫 db.close()
在 SQLiteDatabase分贝
传过来的参数给你的函数。您应该只关闭数据库已打开自己和关闭这种方式将导致异常,尽管不同的功能。
What is definitely wrong is that you call db.close()
on the SQLiteDatabase db
passed in as a parameter to your function. You should only close databases you opened yourself and closing it this way will lead to an exception, albeit a different one.
这篇关于附近&QUOT SQLite的语法错误; CREATE TABLE"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!