This is an automated email from the ASF dual-hosted git repository.

Caideyipi pushed a commit to branch codex/jdbc-driver-info
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/codex/jdbc-driver-info by this 
push:
     new 764db05e8e5 Reject closed JDBC wrapper and result set operations
764db05e8e5 is described below

commit 764db05e8e5eb17ed8fd68f7093c9c813f81d8c1
Author: Caideyipi <[email protected]>
AuthorDate: Tue Jun 9 16:25:11 2026 +0800

    Reject closed JDBC wrapper and result set operations
---
 .../org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java  | 48 ++++++++++++++++++----
 .../apache/iotdb/jdbc/IoTDBPreparedStatement.java  |  4 +-
 .../java/org/apache/iotdb/jdbc/IoTDBStatement.java |  4 +-
 .../iotdb/jdbc/IoTDBTablePreparedStatement.java    |  4 +-
 .../apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java  | 16 ++++++++
 .../iotdb/jdbc/IoTDBPreparedStatementTest.java     |  2 +
 .../org/apache/iotdb/jdbc/IoTDBStatementTest.java  |  2 +
 .../jdbc/IoTDBTablePreparedStatementTest.java      |  2 +
 8 files changed, 72 insertions(+), 10 deletions(-)

diff --git 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java
index fa889371bdc..99b856e446b 100644
--- 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java
+++ 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java
@@ -181,11 +181,13 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    checkOpen();
     return JdbcWrapperUtils.isWrapperFor(this, iface);
   }
 
   @Override
   public <T> T unwrap(Class<T> iface) throws SQLException {
+    checkOpen();
     return JdbcWrapperUtils.unwrap(this, iface);
   }
 
@@ -210,7 +212,8 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public void clearWarnings() {
+  public void clearWarnings() throws SQLException {
+    checkOpen();
     warningChain = null;
   }
 
@@ -267,6 +270,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -276,6 +280,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public BigDecimal getBigDecimal(String columnName) throws SQLException {
+    checkOpen();
     String value = getValueByName(columnName);
     if (value == null) {
       return null;
@@ -315,6 +320,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public Blob getBlob(int arg0) throws SQLException {
+    checkOpen();
     try {
       final TSDataType dataType = ioTDBRpcDataSet.getDataType(arg0);
       if (dataType == null) {
@@ -337,6 +343,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public Blob getBlob(String arg0) throws SQLException {
+    checkOpen();
     try {
       final TSDataType dataType = ioTDBRpcDataSet.getDataType(arg0);
       if (dataType == null) {
@@ -359,6 +366,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public boolean getBoolean(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getBoolean(columnIndex);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -368,6 +376,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public boolean getBoolean(String columnName) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getBoolean(columnName);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -387,6 +396,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public byte[] getBytes(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       final TSDataType dataType = ioTDBRpcDataSet.getDataType(columnIndex);
       if (dataType == null) {
@@ -409,6 +419,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public byte[] getBytes(String columnName) throws SQLException {
+    checkOpen();
     try {
       final TSDataType dataType = ioTDBRpcDataSet.getDataType(columnName);
       if (dataType == null) {
@@ -449,7 +460,8 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public int getConcurrency() {
+  public int getConcurrency() throws SQLException {
+    checkOpen();
     return ResultSet.CONCUR_READ_ONLY;
   }
 
@@ -481,6 +493,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public double getDouble(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       if (TSDataType.FLOAT == ioTDBRpcDataSet.getDataType(columnIndex)) {
         return ioTDBRpcDataSet.getFloat(columnIndex);
@@ -493,6 +506,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public double getDouble(String columnName) throws SQLException {
+    checkOpen();
     try {
       if (TSDataType.FLOAT == ioTDBRpcDataSet.getDataType(columnName)) {
         return ioTDBRpcDataSet.getFloat(columnName);
@@ -504,24 +518,28 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public int getFetchDirection() {
+  public int getFetchDirection() throws SQLException {
+    checkOpen();
     return ResultSet.FETCH_FORWARD;
   }
 
   @Override
   public void setFetchDirection(int direction) throws SQLException {
+    checkOpen();
     if (direction != ResultSet.FETCH_FORWARD) {
       throw new 
SQLException(String.format(JdbcMessages.DIRECTION_NOT_SUPPORTED, direction));
     }
   }
 
   @Override
-  public int getFetchSize() {
+  public int getFetchSize() throws SQLException {
+    checkOpen();
     return ioTDBRpcDataSet.getFetchSize();
   }
 
   @Override
   public void setFetchSize(int fetchSize) throws SQLException {
+    checkOpen();
     if (fetchSize < 0) {
       throw new SQLException(
           String.format(JdbcMessages.FETCH_SIZE_MUST_BE_NON_NEGATIVE, 
fetchSize));
@@ -531,6 +549,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public float getFloat(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getFloat(columnIndex);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -540,6 +559,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public float getFloat(String columnName) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getFloat(columnName);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -549,11 +569,13 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public int getHoldability() throws SQLException {
+    checkOpen();
     return ResultSet.HOLD_CURSORS_OVER_COMMIT;
   }
 
   @Override
   public int getInt(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getInt(columnIndex);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -563,6 +585,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public int getInt(String columnName) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getInt(columnName);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -572,6 +595,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public long getLong(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getLong(columnIndex);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -581,6 +605,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public long getLong(String columnName) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getLong(columnName);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -642,6 +667,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public Object getObject(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return getObject(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -651,6 +677,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public Object getObject(String columnName) throws SQLException {
+    checkOpen();
     return getObjectByName(columnName);
   }
 
@@ -720,12 +747,14 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public Statement getStatement() {
+  public Statement getStatement() throws SQLException {
+    checkOpen();
     return this.statement;
   }
 
   @Override
   public String getString(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getString(columnIndex);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -735,6 +764,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public String getString(String columnName) throws SQLException {
+    checkOpen();
     return getValueByName(columnName);
   }
 
@@ -761,6 +791,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public Timestamp getTimestamp(int columnIndex) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getTimestamp(columnIndex);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -770,6 +801,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
 
   @Override
   public Timestamp getTimestamp(String columnName) throws SQLException {
+    checkOpen();
     try {
       return ioTDBRpcDataSet.getTimestamp(columnName);
     } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
@@ -788,7 +820,8 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public int getType() {
+  public int getType() throws SQLException {
+    checkOpen();
     return ResultSet.TYPE_FORWARD_ONLY;
   }
 
@@ -813,7 +846,8 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public SQLWarning getWarnings() {
+  public SQLWarning getWarnings() throws SQLException {
+    checkOpen();
     return warningChain;
   }
 
diff --git 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
index 0accd32c92b..91d218dc0ad 100644
--- 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
+++ 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBPreparedStatement.java
@@ -215,11 +215,13 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
 
       @Override
       public <T> T unwrap(Class<T> iface) throws SQLException {
+        checkConnection("getParameterMetaData");
         return JdbcWrapperUtils.unwrap(this, iface);
       }
 
       @Override
-      public boolean isWrapperFor(Class<?> iface) {
+      public boolean isWrapperFor(Class<?> iface) throws SQLException {
+        checkConnection("getParameterMetaData");
         return JdbcWrapperUtils.isWrapperFor(this, iface);
       }
     };
diff --git 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
index 6bc1f03fbd2..e77eb4577a9 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java
@@ -183,12 +183,14 @@ public class IoTDBStatement implements Statement {
   }
 
   @Override
-  public boolean isWrapperFor(Class<?> iface) {
+  public boolean isWrapperFor(Class<?> iface) throws SQLException {
+    checkConnection("isWrapperFor");
     return JdbcWrapperUtils.isWrapperFor(this, iface);
   }
 
   @Override
   public <T> T unwrap(Class<T> iface) throws SQLException {
+    checkConnection("unwrap");
     return JdbcWrapperUtils.unwrap(this, iface);
   }
 
diff --git 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatement.java
 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatement.java
index 9760b8fd528..e23d4d49cd7 100644
--- 
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatement.java
+++ 
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatement.java
@@ -339,11 +339,13 @@ public class IoTDBTablePreparedStatement extends 
IoTDBStatement implements Prepa
 
       @Override
       public <T> T unwrap(Class<T> iface) throws SQLException {
+        checkConnection("getParameterMetaData");
         return JdbcWrapperUtils.unwrap(this, iface);
       }
 
       @Override
-      public boolean isWrapperFor(Class<?> iface) {
+      public boolean isWrapperFor(Class<?> iface) throws SQLException {
+        checkConnection("getParameterMetaData");
         return JdbcWrapperUtils.isWrapperFor(this, iface);
       }
     };
diff --git 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java
 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java
index b3b43356447..5c85c471017 100644
--- 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java
+++ 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java
@@ -295,10 +295,26 @@ public class IoTDBJDBCResultSetTest {
     resultSet.close();
 
     Assert.assertTrue(resultSet.isClosed());
+    Assert.assertThrows(SQLException.class, () -> 
resultSet.isWrapperFor(ResultSet.class));
+    Assert.assertThrows(SQLException.class, () -> 
resultSet.unwrap(ResultSet.class));
+    Assert.assertThrows(SQLException.class, () -> resultSet.clearWarnings());
     Assert.assertThrows(SQLException.class, () -> resultSet.next());
+    Assert.assertThrows(SQLException.class, () -> resultSet.getBigDecimal(1));
+    Assert.assertThrows(SQLException.class, () -> resultSet.getBlob(1));
+    Assert.assertThrows(SQLException.class, () -> resultSet.getBytes(1));
+    Assert.assertThrows(SQLException.class, () -> resultSet.getConcurrency());
+    Assert.assertThrows(SQLException.class, () -> 
resultSet.getFetchDirection());
+    Assert.assertThrows(
+        SQLException.class, () -> 
resultSet.setFetchDirection(ResultSet.FETCH_FORWARD));
+    Assert.assertThrows(SQLException.class, () -> resultSet.getFetchSize());
+    Assert.assertThrows(SQLException.class, () -> resultSet.setFetchSize(1));
+    Assert.assertThrows(SQLException.class, () -> resultSet.getHoldability());
+    Assert.assertThrows(SQLException.class, () -> resultSet.getStatement());
     Assert.assertThrows(SQLException.class, () -> resultSet.getString(1));
     Assert.assertThrows(SQLException.class, () -> 
resultSet.findColumn("Time"));
     Assert.assertThrows(SQLException.class, () -> resultSet.getMetaData());
+    Assert.assertThrows(SQLException.class, () -> resultSet.getType());
+    Assert.assertThrows(SQLException.class, () -> resultSet.getWarnings());
     Assert.assertThrows(SQLException.class, () -> resultSet.wasNull());
   }
 
diff --git 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
index a147f6b8eb9..80781c2e7dd 100644
--- 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
+++ 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBPreparedStatementTest.java
@@ -153,6 +153,8 @@ public class IoTDBPreparedStatementTest {
         SQLException.class,
         () -> ps.setBinaryStream(1, new ByteArrayInputStream(new byte[] {1}), 
1));
     assertThrows(SQLException.class, () -> ps.getParameterMetaData());
+    assertThrows(SQLException.class, () -> 
metadata.isWrapperFor(ParameterMetaData.class));
+    assertThrows(SQLException.class, () -> 
metadata.unwrap(ParameterMetaData.class));
     assertThrows(SQLException.class, () -> metadata.getParameterCount());
     assertThrows(SQLException.class, () -> metadata.getPrecision(1));
   }
diff --git 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
index cee793b773e..a5cad7a79d8 100644
--- 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
+++ 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBStatementTest.java
@@ -153,6 +153,8 @@ public class IoTDBStatementTest {
     assertThrows(SQLException.class, () -> statement.executeBatch());
     assertThrows(SQLException.class, () -> statement.addBatch("select 1"));
     assertThrows(SQLException.class, () -> statement.clearBatch());
+    assertThrows(SQLException.class, () -> 
statement.isWrapperFor(Statement.class));
+    assertThrows(SQLException.class, () -> statement.unwrap(Statement.class));
     assertThrows(SQLException.class, () -> statement.getFetchSize());
     assertThrows(SQLException.class, () -> statement.getWarnings());
   }
diff --git 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatementTest.java
 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatementTest.java
index 50334a25156..91c86b4c390 100644
--- 
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatementTest.java
+++ 
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBTablePreparedStatementTest.java
@@ -182,6 +182,8 @@ public class IoTDBTablePreparedStatementTest {
         SQLException.class,
         () -> ps.setBinaryStream(1, new ByteArrayInputStream(new byte[] {1}), 
1));
     assertThrows(SQLException.class, () -> ps.getParameterMetaData());
+    assertThrows(SQLException.class, () -> 
metadata.isWrapperFor(ParameterMetaData.class));
+    assertThrows(SQLException.class, () -> 
metadata.unwrap(ParameterMetaData.class));
     assertThrows(SQLException.class, () -> metadata.getParameterCount());
     assertThrows(SQLException.class, () -> metadata.getParameterType(1));
   }

Reply via email to