import java.sql.*; public class OutFunc { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5820/jurka","jurka",""); try { testNotEnoughRegisters(conn); } catch (Exception e) { e.printStackTrace(); } try { testTooManyRegisters(conn); } catch (Exception e) { e.printStackTrace(); } } private static void testNotEnoughRegisters(Connection conn) throws SQLException { Statement stmt = conn.createStatement(); stmt.execute("CREATE OR REPLACE FUNCTION myiofunc(a INOUT int, b OUT int) AS 'BEGIN b := a; a := 1; END;' LANGUAGE plpgsql"); CallableStatement cs = conn.prepareCall("{call myiofunc(?,?)}"); cs.setInt(1,2); cs.registerOutParameter(2,Types.INTEGER); cs.execute(); System.out.println(cs.getInt(1)); System.out.println(cs.getInt(2)); } private static void testTooManyRegisters(Connection conn) throws SQLException { Statement stmt = conn.createStatement(); stmt.execute("CREATE OR REPLACE FUNCTION myif(a INOUT int, b IN int) AS 'BEGIN a := b; END;' LANGUAGE plpgsql"); CallableStatement cs = conn.prepareCall("{call myif(?,?)}"); cs.setInt(1,1); cs.setInt(2,2); cs.registerOutParameter(1,Types.INTEGER); cs.registerOutParameter(2,Types.INTEGER); cs.execute(); System.out.println(cs.getInt(1)); System.out.println(cs.getInt(2)); } }