import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.DriverManager; import java.sql.Types; import java.sql.SQLException; import org.postgresql.PGStatement; public class PreparedCastTest { public static void main(String[] args) { Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { c = DriverManager.getConnection(args[0], args[1], args[2]); ps = c.prepareStatement("select foo(?)"); ( (PGStatement) ps ).setUseServerPrepare(true); //ps.setInt(1, 42); //ps.setObject(1, new Integer(42), Types.INTEGER); ps.setObject(1, null, Types.INTEGER); rs = ps.executeQuery(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } finally { if (rs != null) { try { rs.close(); } catch (Throwable t) {} } if (ps != null) { try { ps.close(); } catch (Throwable t) {} } if (c != null) { try { c .close(); } catch (Throwable t) {} } } } }