PreparedStatement IN clause alternatives?

前端 未结 30 3889
情歌与酒
情歌与酒 2020-11-21 05:19

What are the best workarounds for using a SQL IN clause with instances of java.sql.PreparedStatement, which is not supported for multiple values du

30条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 05:54

    You could use setArray method as mentioned in this javadoc:

    PreparedStatement statement = connection.prepareStatement("Select * from emp where field in (?)");
    Array array = statement.getConnection().createArrayOf("VARCHAR", new Object[]{"E1", "E2","E3"});
    statement.setArray(1, array);
    ResultSet rs = statement.executeQuery();
    

提交回复
热议问题