1

错误:

 10-30 03:42:14.451: E/SQLiteLog(1633): (1) near "TEXT": syntax error
 10-30 03:42:14.502: E/AndroidRuntime(1633): android.database.sqlite.SQLiteException: near "TEXT": syntax error (code 1): , while compiling: Create Table user_info(_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,  name TEXT ,  bdate TEXT ,  adate TEXT ,  check TEXT ,  bmessage TEXT ,  amessage TEXT):

当这种类型的错误发生时。

下面给出sql代码:

     String TABLE_SQL="Create Table "+TABLE_NAME
            +"(_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "
            +" name TEXT , "
            +" bdate TEXT , "
            +" adate TEXT , "
            +" check TEXT , "
            +" bmessage TEXT , "
            +" amessage TEXT): ";
4

3 回答 3

1

这里出现了两个问题,第一个是语法错误,另一个是变量名“check”。我们知道 check 是在 SQL 中使用的关键字。所以要从中恢复,我们可以更改变量名称,例如:checkSelection。

所以上面的代码应该是: String TABLE_SQL="Create Table "+TABLE_NAME +"(_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , " +" name TEXT , " +" bdate TEXT , " +" adate TEXT , " +"checkSelection TEXT , " //here replaced 'check' with 'checkSelection' +" bmessage TEXT , " +" amessage TEXT); ";// here replaced: with;`

我认为这是摆脱它的正确方法之一。

于 2016-01-14T05:13:21.323 回答
0

改变:

  String TABLE_SQL="Create Table "+TABLE_NAME
            +"(_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "
            +" name TEXT , "
            +" bdate TEXT , "
            +" adate TEXT , "
            +" check TEXT , "
            +" bmessage TEXT , "
            +" amessage TEXT); ";// here,replace `:` with `;`

你把:而不是;放在最后一行。所以将其替换为;.

于 2013-10-30T04:01:51.983 回答
0

:在行尾删除

String TABLE_SQL="Create Table "+TABLE_NAME
            +"(_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "
            +" name TEXT , "
            +" bdate TEXT , "
            +" adate TEXT , "
            +" check TEXT , "
            +" bmessage TEXT , "
            +" amessage TEXT): ";

用下面的代码替换上面的代码,

String TABLE_SQL="Create Table "+TABLE_NAME
            +"(_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , "
            +" name TEXT , "
            +" bdate TEXT , "
            +" adate TEXT , "
            +" check TEXT , "
            +" bmessage TEXT , "
            +" amessage TEXT)";
于 2013-10-30T04:02:00.487 回答