android sqlite语法错误选择

时间:2011-12-19 18:53:44

标签: android sqlite

调用此方法时出错:

public void updateEnrolled(String name, String group, boolean enrolled) 
{
    Cursor cursor = database.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
            KEY_DATE, KEY_PROFESSOR, KEY_LOCATION, KEY_HOURSTART, KEY_HOUREND, KEY_WEEK}, KEY_NAME + "=" +name, null, null, null, null, null);// + " AND " + KEY_GROUP + "=" + group
    cursor.moveToFirst();
    while(!cursor.isAfterLast())
    {
        long rowId = cursor.getInt(cursor.getColumnIndex(KEY_ROWID));
        String date = cursor.getString(cursor.getColumnIndex(KEY_DATE));
        String professor = cursor.getString(cursor.getColumnIndex(KEY_PROFESSOR));
        String location = cursor.getString(cursor.getColumnIndex(KEY_LOCATION));
        String hourStart = cursor.getString(cursor.getColumnIndex(KEY_HOURSTART));
        String hourEnd = cursor.getString(cursor.getColumnIndex(KEY_HOUREND));
        int week = cursor.getInt(cursor.getColumnIndex(KEY_WEEK));
        updateLesson(rowId,name,date,professor,location,hourStart,hourEnd,week,group,enrolled);
    }
    cursor.close();
}

我得到的错误是:

android.database.sqlite.SQLiteException: near "Electronics": syntax error: , while compiling: SELECT DISTINCT _id, date, professor, location, hourStart, hourEnd, week FROM lesson WHERE name=Analog Electronics: lab

我也尝试了另一个输入,每次输入错误的名字的第二个单词时都是这样。 任何人都可以帮助我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

在database.query方法中尝试KEY_NAME + "= \"" + name + "\""