如何在Android中使用SQLITE中的准备语句?如何在Android中使用SQLITE中的准备语句?
3 回答
梦里花落0921
TA贡献1772条经验 获得超6个赞
SQLiteDatabase db = dbHelper.getWritableDatabase();SQLiteStatement stmt = db.compileStatement("SELECT * FROM Country WHERE code = ?");
stmt.bindString(1, "US");stmt.execute();
慕哥9229398
TA贡献1877条经验 获得超6个赞
SQLiteDatabase db = dbHelper.getWritableDatabase();public Cursor fetchByCountryCode(String strCountryCode){
/**
* SELECT * FROM Country
* WHERE code = US
*/
return cursor = db.query(true,
"Country", /**< Table name. */
null, /**< All the fields that you want the
cursor to contain; null means all.*/
"code=?", /**< WHERE statement without the WHERE clause. */
new String[] { strCountryCode }, /**< Selection arguments. */
null, null, null, null);}/** Fill a cursor with the results. */Cursor c = fetchByCountryCode("US");
/** Retrieve data from the fields. */String strCountryCode = c.getString(cursor.getColumnIndex("code"));
/** Assuming that you have a field/column with the name "country_name"
*/String strCountryName = c.getString(cursor.getColumnIndex("country_name"));- 3 回答
- 0 关注
- 513 浏览
添加回答
举报
0/150
提交
取消
