import java.sql.*; // Run with one argument: a JDBC url to connect to. public class TestMultiInsert { public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection c = DriverManager.getConnection(args[0]); c.setAutoCommit(false); Statement s = c.createStatement(); s.executeUpdate("CREATE SEQUENCE seq_i"); s.executeUpdate("CREATE SEQUENCE seq_j"); s.executeUpdate("CREATE TEMP TABLE t1 (i int4 default nextval('seq_i'), zz text)"); s.executeUpdate("CREATE TEMP TABLE t2 (j int4 default nextval('seq_j'), i int4, zz text)"); PreparedStatement ps = c.prepareStatement("INSERT INTO t1(zz) VALUES (?); INSERT INTO t2(i,zz) VALUES(currval('seq_i'),?); SELECT currval('seq_i'), currval('seq_j')"); ps.setString(1, "A"); ps.setString(2, "B"); boolean resultType = ps.execute(); int updateCount = ps.getUpdateCount(); int num = 1; do { System.err.println("Result #" + num + " has resultset? " + resultType + " update count " + updateCount); ++num; resultType = ps.getMoreResults(); updateCount = ps.getUpdateCount(); } while (resultType || updateCount != -1); s.close(); c.rollback(); c.close(); } }