2013-07-01 107 views
-1

我想從名稱(KEY_CUSTOMER_NAME)匹配給定名稱的表中獲取ID。 表包含三個coloumn KEY_CUSTOMER_ID,KEY_CUSTOMER_NAME,KEY_CUSTOMER_GENDER列索引超出範圍例外

我的查詢

db.rawQuery("SELECT id FROM " +TABLE_NAME +" where name = '"+names+"'", null); 

其運行良好...但我想用用sqlite的查詢方法來執行它的Android

db.query(TABLE_NAME, new String[]{ KEY_CUSTOMER_ID }, KEY_CUSTOMER_NAME, new String[] { String.valueOf(names) }, null, null, null); 

但其顯示超出範圍的例外。

+0

'KEY_CUSTOMER_NAME' =>'KEY_CUSTOMER_NAME +' – Selvin

+0

是什麼'KEY_CUSTOMER_ID','KEY_CUSTOMER_NAME'和'names' 「=?」? –

+0

謝謝...它的工作...空間問題.. @ Selvin – veronica

回答

1

這應該工作:

db.query(TABLE_NAME, new String[] { KEY_CUSTOMER_ID, KEY_CUSTOMER_NAME }, KEY_CUSTOMER_NAME + "=?",new String[] { String.valueOf(id) }, null, null, null, null); 
+0

但主要問題是空間... – veronica

0

試試這個

db.query(TABLE_NAME, new String[]{ KEY_CUSTOMER_ID }, "KEY_CUSTOMER_NAME =?", new String[] { String.valueOf(names) }, null, null, null); 

凡KEY_CUSTOMER_NAME應該是表

的列名
0

試試看這樣。

db.query(TABLE_NAME, new String[]{ KEY_CUSTOMER_ID }, KEY_CUSTOMER_NAME+" = "+new String[] { String.valueOf(names) }, null, null, null, null);