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

时间:2014-04-16 17:35:52

标签: android sqlite cursor

在检索以下检索代码时,我反复遇到错误:

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;
}

遇到的错误是:

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}

1 个答案:

答案 0 :(得分:0)

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

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