简体   繁体   English

Android中SQlite数据库代码中的游标错误

[英]Cursor error in SQlite database code in Android

There is an error which i repeatedly encounter while retrieving the following retrieval code: 检索以下检索代码时,我反复遇到错误:

public VTB getCommands(String variation) {  
    VTB vtb=new VTB();
    SQLiteDatabase db = this.getReadableDatabase(); 
    try
    {

    Cursor cursor;
    cursor=db.query(TABLE_NAME, new String[]{ COMMANDS,VARIATIONS},VARIATIONS+"="+variation,null, null, null, null);

        if(cursor!=null) 
                cursor.moveToFirst(); 
vtb = new VTB(cursor.getString(0),cursor.getString(1)); 

    }
    catch(SQLException e)
    {
        Log.e("DB ERROR", e.toString());
        e.printStackTrace();
    }
    return vtb;
}

The error encountered is: 遇到的错误是:

04-16 22:52:43.921: I/Database(382): sqlite returned: error code = 1, msg = near "First": syntax error
04-16 22:52:43.921: E/DB ERROR(382): android.database.sqlite.SQLiteException: near "First": syntax error: , while compiling: SELECT command, variations FROM VTB WHERE variations=Call First Name{F}, last name{L}

尝试使用参数化查询,例如:

cursor=db.query(TABLE_NAME, new String[]{ COMMANDS,VARIATIONS},VARIATIONS+"= ?", new String[]{variation},null, null, null, null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM