我有這段代碼不起作用。誰能告訴我我做錯了什麼?如下Android將變量添加到數據庫查詢
String option = names.getText().toString();
Cursor c = db.rawQuery("SELECT * from numbers Where fname=option", null);
我有這段代碼不起作用。誰能告訴我我做錯了什麼?如下Android將變量添加到數據庫查詢
String option = names.getText().toString();
Cursor c = db.rawQuery("SELECT * from numbers Where fname=option", null);
變化:
Cursor c = db.rawQuery("SELECT * from numbers Where fname='"+option+"' ", null);
哈哈謝謝!我之前有''+ option +'',謝謝! – user2673161
y享受!!!!!! –
試試這個
String query = "SELECT * from numbers Where fname='"+ option +"'";
database.execSQL(query);
This Works awesomely Also! – user2673161
歡迎,請接受答案 –
更喜歡使用預處理語句與?
佔位符。
String option = names.getText().toString();
String query = "SELECT * from numbers Where fname = ?"
Cursor c = db.rawQuery(query, new String[] {option});
「SELECT * from numbers where fname =」+ option – KOTIOS