开发者

Converting Java Set to an argument for PreparedStatement setString method

What would be 开发者_如何学编程the simplest way to covert a Set<String> to an argument for Oracle in (?)? I am already using PreparedStatement for that.


You can't. The query must have one placeholder (?) for each of the elements in the set. And you have to bind every element of the set:

If your set has three elements, your prepared statement must look like this :

String sql = "select foo.* from FOO foo where foo.id in (?, ?, ?)";

and you must iterate through the set and bind each element individually:

int i = 1;
for (String s : setOfStrings) {
    statement.setString(i, s);
    i++;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜