(Android)继续在SQL语句上获得错误

时间:2013-06-21 22:36:59

标签: android sql database

我在Android应用程序中创建表时遇到了麻烦。

这是我的错误:

06-21 23:29:58.490: E/SQLiteLog(19571): (1) near "index": syntax error
06-21 23:29:58.820: E/InfiniDatabase(19571): Creating Index Table Failed
06-21 23:29:58.820: E/InfiniDatabase(19571): android.database.sqlite.SQLiteException: near "index": syntax error (code 1): , while compiling: CREATE TABLE index (_id INTEGER PRIMARY KEY)

这是我正在使用的“测试”声明,因为我的完整陈述就是不玩球。我对SQL没用 - 是我还是电脑?

这是Java片段:

//used to create are initial index table...
@Override
public void onCreate(SQLiteDatabase db) 
{
    Log.d(TAG_NAME, "Now Creating Index Table");
    try{
        final String INDEX_TABLE_CREATE = "CREATE TABLE " + INDEX_TABLE_NAME +
                " (" + 
                COL_ID + " INTEGER PRIMARY KEY" + ")";

        db.execSQL(INDEX_TABLE_CREATE);

        Log.d(TAG_NAME,"Created New Index Table");
    }
    catch(SQLException e)
    {
        Log.e(TAG_NAME, "Creating Index Table Failed", e);
    }
}

2 个答案:

答案 0 :(得分:3)

您不能使用名称“index”作为表的名称,因为它是sqlite中的关键字 请参阅此链接http://www.sqlite.org/lang_keywords.html

答案 1 :(得分:0)

你错过了分号

final String INDEX_TABLE_CREATE = "CREATE TABLE " + INDEX_TABLE_NAME +
            " (" + 
            COL_ID + " INTEGER PRIMARY KEY" + ");";