我正在尝试从我的应用程序中SQLite DB中的一个表中编写一个select查询,其中存在数据。
这是SQL.table有这些列 - id(INTEGER),start_time(INTEGER),category(TEXT)
select category from tuuserid_pref where id = (select max(id) from tuuserid_pref
where start_time < '1242');
顺便说一下,我想绑定1242中显示的值,我在Integer变量中有这个值。
我编写了选择,插入和更新而没有绑定参数,它们使用db.execSQL和db.rawQuery函数工作,但只是无法计算绑定参数。
非常感谢任何帮助。
答案 0 :(得分:2)
您需要修改您的select语句,如下所示:
select category from tuuserid_pref where id =
(select max(id) from tuuserid_pref where start_time < ?);
然后使用以下rawQuery
电话:
rawQuery(String sql, String[] selectionArgs)
将您的变量传递到包含在String []
中的第二个参数,该参数应该为您提供如下语句:
db.rawQuery(sqlStatement, new String[] { String.valueOf(myInt) });
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html