From a19be9f304c21222177781f9bb765849d610772d Mon Sep 17 00:00:00 2001 From: justbk <249396768@qq.com> Date: Thu, 15 Dec 2022 21:07:19 +0800 Subject: [PATCH] =?UTF-8?q?implement=20new=20setObject(int,Object,=20SQLTy?= =?UTF-8?q?pe)=20interface=20=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/postgresql/jdbc/PgPreparedStatement.java | 8 +++++++- .../test/jdbc2/PreparedStatementTest.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java b/pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java index 63adf81..7d3984f 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 e9227d6..5705fac 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()); + } + } } -- Gitee