import java.sql.*; import org.postgresql.*; import org.postgresql.fastpath.*; public class FP { public static void main(String margs[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka",""); Statement stmt = conn.createStatement(); // Create a function to call via fastpath that will // throw an exception. // stmt.execute("CREATE OR REPLACE FUNCTION myfpfunc() RETURNS int AS 'BEGIN RAISE EXCEPTION ''ex''; RETURN 1; END;' LANGUAGE plpgsql"); // Lookup oid of function we just created. ResultSet rs = stmt.executeQuery("SELECT oid FROM pg_proc WHERE proname='myfpfunc'"); rs.next(); int fnid = rs.getInt(1); rs.close(); // Call the function catching any error. Fastpath fp = ((PGConnection)conn).getFastpathAPI(); FastpathArg[] args = new FastpathArg[0]; try { fp.fastpath(fnid, true, args); } catch (SQLException sqle) { sqle.printStackTrace(); } // Check that the connection still works by executing // something else. rs = stmt.executeQuery("SELECT 1"); rs.next(); System.out.println(rs.getInt(1)); rs.close(); stmt.close(); conn.close(); } }