我收到android.database.sqlite.SQLiteException" SELECTamountFROMnilanjan_tableWHEREName":语法错误(代码1):

时间:2017-06-18 05:42:48

标签: sqlite

我收到android.database.sqlite.SQLiteException" SELECTamountFROMnilanjan_tableWHEREName&#34 ;:语法错误(代码1):

public Cursor getItemID(String name)
{
    SQLiteDatabase db =this.getWritableDatabase();
    String query = "SELECT" + COL_3 + "FROM" + TABLE_NAME +"WHERE" + COL_2 + " = '" + name + "'" ;
    Cursor data = db.rawQuery(query,null);
    return data;
}

1 个答案:

答案 0 :(得分:0)

您的错误消息中的

"SELECTamountFROMnilanjan_tableWHEREName"是您作为查询执行的连接的结果。

您需要在关键字之间添加空格以创建有效的查询。:

"SELECT " + COL_3 + " FROM " + TABLE_NAME + " WHERE " + COL_2 + " = '" + name + "'" ;