OK, my fault, I didn't understand the syntax, so the correct statement is "select pk from table(x int=?) t inner join mytest on t.x=mytest.col" and it works, but what about delete statements? What kind of syntax must I use?
Il giorno martedì 11 dicembre 2012 17:27:23 UTC+1, Noel Grandin ha scritto: > > Try reading the documentation again. > > > On Tue, Dec 11, 2012 at 3:57 PM, Penta <andrea.qu...@gmail.com<javascript:> > > wrote: > >> 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-da...@googlegroups.com<javascript:> >> . >> To unsubscribe from this group, send email to >> h2-database...@googlegroups.com <javascript:>. >> For more options, visit this group at >> http://groups.google.com/group/h2-database?hl=en. >> > > -- 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/-/m9xocTEMStAJ. 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.