diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java index 63adf813404f01f17799fe1721329a8b88695fac..7d3984f127d51f880f6d885626a78acae34a89cc 100644 --- a/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java +++ b/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java @@ -56,6 +56,7 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.RowId; import java.sql.SQLException; +import java.sql.SQLType; import java.sql.SQLXML; import java.sql.Time; import java.sql.Timestamp; @@ -903,7 +904,12 @@ class PgPreparedStatement extends PgStatement implements PreparedStatement { GT.tr("Cannot convert an instance of {0} to type {1}", fromType, toType), PSQLState.INVALID_PARAMETER_TYPE, cause); } - + + @Override + public void setObject(final int parameterIndex, final Object x, final SQLType targetSqlType) throws SQLException { + setObject(parameterIndex, x, targetSqlType.getVendorTypeNumber()); + } + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { setObject(parameterIndex, x, targetSqlType, -1); } diff --git a/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java index e9227d652c786299dfb9d8a958bb6b5441b1e590..5705fac34ab31c4317b51142d6cd33c1413d9785 100644 --- a/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java +++ b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/PreparedStatementTest.java @@ -32,6 +32,7 @@ import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; +import java.sql.JDBCType; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -1465,4 +1466,17 @@ public class PreparedStatementTest extends BaseTest4 { log.setLevel(prevLevel); } } + + @Test + public void testNewObjectInterface() throws SQLException { + //TestUtil.createTable(con, "inttable", "a int"); + String sql = "insert into inttable values (?)"; + Integer insertVal = new Integer(1); + try (PreparedStatement ps = con.prepareStatement(sql)) { + ps.setObject(1, insertVal, JDBCType.INTEGER); + ps.execute(); + } catch (SQLException sqlExp) { + Assert.fail("can't run here! err=" + sqlExp.toString()); + } + } }