Started playing with this some today. Here is what I found for PostgreSQL. Given a function defined to return a refcursor, here is what seems like is needed:
{code} // Note the need for the leading '? ='... CallableStatement callableStatement = connection.prepareCall( "{? = call allPersons()}" ); // Have not tried with Java 8 and the explicit Types#REF_CURSOR added there... callableStatement.registerOutParameter( 1, Types.OTHER );
boolean hasResults = callableStatement.execute(); assertFalse( hasResults ); assertEquals( -1, callableStatement.getUpdateCount() );
// Can't even use getObject( 1, ResultSet.class ) since the postgresql jdbc driver does not implement it... ResultSet results = (ResultSet) callableStatement.getObject( 1 ); {code}
So against postgresql, when a parameter is registered with mode of REF_CURSOR we need to: # Know to append the `? =' # Validate that the REF_CURSOR is registered positionally and and that its position is 1 # Disallow named parameters since the spec does not allow named/positional mixing and the REF_CURSOR parameter is implicitly positional # Register the JDBC parameter as Types#OTHER
|