问题描述
我想执行使用SQLite在Android的rawQuery()下面的SQL查询。结果
但我得到结果
android.database.sqlite.SQLiteException:近状态:语法错误:,在编译:选择emp_id,日期,结束日期fromleave_plans1where状态=?
I want to execute the following SQL query using SQLite's rawQuery() in Android.
But I am getting
"android.database.sqlite.SQLiteException: near "status": syntax error: , while compiling: select emp_id,start_date,end_date fromleave_plans1where status = ?"
SQL查询:选择emp_id,起始日期,从leave_plans END_DATE,其中状态=批准或状态=待定
SQL query : select emp_id,start_date,end_date from leave_plans where status="approved" or status="pending"
和rawQuery我已经使用:
and rawQuery i have used :
db.rawQuery("select emp_id,start_date,end_date from" + TABLE_NAME + "where status = ?",new String[] {"approved","pending"});
请帮忙
由于结果
sneha
Thanks
sneha
推荐答案
试试这个code:
String[] columns = { "emp_id", "start_date", "end_date" };
String[] whereArguments = { "approved", "pending" };
Cursor cursor = db.query(TABLE_NAME, columns, "status = ? OR status = ?", whereArguments, null, null, null);
这两个问号是在查询的第三个参数必要
调用每个?
字符引用一个元素在 whereArguments
阵列。因此,这个调用将转化为:
The two question marks are necessary in the third argument in the query
call as each ?
character references one element in the whereArguments
array. So this call will translate to:
选择emp_id,日期,结束日期从{} TABLE_NAME WHERE状态=批准或状态=待定;
SELECT emp_id, start_date, end_date FROM {TABLE_NAME} WHERE status = "approved" OR status = "pending";
(通过任何字符串常量它重新presents其中{} TABLE_NAME显然将取代)。
(Where {TABLE_NAME} will obviously be replace by whatever String constant it represents.)
这篇关于rawQuery()语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!