2012-08-16 64 views
0

的,我想做到以下幾點的Java + Oracle數據庫:如何查詢數據庫中的一組值

private List<Number> getIds(List<String> names) { 
    String query = "SELECT id FROM months WHERE name IN (?)"; 
      ... 
    } 

我如何通過我的List<String> names到「?」在上面的查詢中?我正在尋找一個動態的解決方案,因爲給定列表的大小會有所不同。

我正在使用Spring 3.0和Oracle 11.2.0.2。

謝謝。

+2

可能重複http://stackoverflow.com/questions/4381791/how-do-you-write- -sql-for-a-prepared-statement-using-a-where-x-in-clause) – Thilo 2012-08-16 09:15:55

+0

也http://stackoverflow.com/questions/178479/preparedstatement-in-clause-alternatives?lq=1 – Thilo 2012-08-16 09:16:56

+0

爲什麼你不要使用jpa? – user902383 2012-08-16 09:18:52

回答

0

爲什麼不使用數據庫函數返回集合並使用CallableStatement從Java調用函數?

通過這樣做,您可以消除將多個值傳遞到IN條件的問題。

問候

的[你怎麼寫使用其中X IN子句一個PreparedStatement的SQL?](