Brian's Waste of Time

Tue, 28 Nov 2006

Oracle's DML Returning and jDBI 2.0pre7

So I broke down and have started adding some database-specific functionality to jDBI. The first bit is a statement customizer which does the downcasts and whatnot to make it convenient to use oracle's dml returning stuff (like "insert into something (id, name) values (something_id_seq.nextval, ?) returning id into ?").

public void testFoo() throws Exception
    Handle h =;

    OracleReturning<Integer> or = new OracleReturning<Integer>(new ResultSetMapper<Integer>() {
        public Integer map(int index, ResultSet r) throws SQLException
            return r.getInt(1);

    or.registerReturnParam(1, OracleTypes.INTEGER);

    h.createStatement("insert into something (id, name) values (17, 'Brian') returning id into ?")
    List<Integer> ids = or.getReturnedResults();

    assertEquals(1, ids.size());
    assertEquals(Integer.valueOf(17), ids.get(0));

This allows for a nice API, without client code downcasts as well, to make use of results returned from DML against Oracle. When I get a chance I'll add one for Postgres as well :-) The code to do it is pretty straightforward. The nice part was that it required no changes to the core of jDBI 2.0 to do this :-)

Pushed 2.0pre7 as well ;-) Have fun!!

0 writebacks [/src/java/jdbi] permanent link