如何在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 關注
- 515 瀏覽
添加回答
舉報
0/150
提交
取消
