Hi, i must use an IN clause in a PreparedStatement, and as stated in http://www.h2database.com/html/performance.html (Prepared Statements and IN(...)) I used the setObject() method.
This is my test case but something is wrong and no records are returned from my PreparedStatement. What's wrong? import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import org.h2.util.JdbcUtils; public class TestSelect { public static void main(String[] args) throws Exception { Connection conn = null; Statement stmt = null; PreparedStatement pstmt = null; ResultSet rs = null; try { Class.forName("org.h2.Driver"); conn = DriverManager.getConnection("jdbc:h2:mem:test", "sa", "sa"); stmt = conn.createStatement(); stmt.execute("create temp table mytest(pk identity, col varchar(20))"); stmt.execute("insert into mytest (col) values('1')"); stmt.execute("insert into mytest (col) values('2')"); stmt.execute("insert into mytest (col) values('3')"); //this doesn't work, no records returned pstmt = conn.prepareStatement("select pk from mytest where col in (?)"); pstmt.setObject(1, new Object[] { "1", "2" }); rs = pstmt.executeQuery(); while (rs.next()) { System.out.println("pk " + rs.getLong(1)); } JdbcUtils.closeSilently(rs); JdbcUtils.closeSilently(pstmt); //this works pstmt = conn.prepareStatement("select pk from mytest where col in ('1','2')"); rs = pstmt.executeQuery(); while (rs.next()) { System.out.println("pk " + rs.getLong(1)); } } finally { JdbcUtils.closeSilently(rs); JdbcUtils.closeSilently(pstmt); JdbcUtils.closeSilently(conn); } } } -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/KNhefTqWTKEJ. To post to this group, send email to h2-database@googlegroups.com. To unsubscribe from this group, send email to h2-database+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.