执行查询时出现SQLiteException

时间:2012-02-21 10:59:44

标签: java android

我想执行ManagedQuery但是我的日志中出现错误:

查询

 Cursor cursor = managedQuery(GroceryListContentProvider.NOTES_URI,projection,Notes.NOTE_TITLE+"="+S+" AND "+ Notes.NOTE_DATE+"="+S1, null, null);

错误记录

02-21 16:00:52.395: E/AndroidRuntime(22534): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.schuemie.GroceryList/net.schuemie.GroceryList.shoppinglist}: android.database.sqlite.SQLiteException: near "new": syntax error: , while compiling: SELECT item_name FROM notes WHERE (title=shop new AND date=12/2/12) ORDER BY title

3 个答案:

答案 0 :(得分:1)

从查询中删除“new”并将引号添加到字符串值

SELECT item_name FROM notes WHERE (title='shop' AND date=12/2/12) ORDER BY title

答案 1 :(得分:0)

你试过这个吗?

title="shop"

title='shop'

答案 2 :(得分:0)

更新

String where = "title='"+nameOfTitle+"' And date="+date+" "; 


Cursor cursor = managedQuery(GroceryListContentProvider.NOTES_URI,null,where,null,null);