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 b6795891307 Fix JDBC parameter and result set edge cases
b6795891307 is described below

commit b6795891307408c2390c73ac56c96998dbd49cd7
Author: Caideyipi <[email protected]>
AuthorDate: Tue Jun 9 14:19:08 2026 +0800

    Fix JDBC parameter and result set edge cases
---
 .../org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java  | 47 ++++++++--------
 .../apache/iotdb/jdbc/IoTDBPreparedStatement.java  | 64 +++++++++++++---------
 .../iotdb/jdbc/IoTDBTablePreparedStatement.java    |  5 +-
 .../apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java  |  4 ++
 .../iotdb/jdbc/IoTDBPreparedStatementTest.java     | 16 ++++--
 .../jdbc/IoTDBTablePreparedStatementTest.java      |  6 ++
 6 files changed, 84 insertions(+), 58 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 302d774105d..f30fcadba86 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
@@ -230,7 +230,10 @@ public class IoTDBJDBCResultSet implements ResultSet {
   }
 
   @Override
-  public int findColumn(String columnName) {
+  public int findColumn(String columnName) throws SQLException {
+    if (!ioTDBRpcDataSet.getColumnNameList().contains(columnName)) {
+      throw new SQLException("Unknown column name: " + columnName);
+    }
     return ioTDBRpcDataSet.findColumn(columnName);
   }
 
@@ -263,7 +266,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
     try {
       return getBigDecimal(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -316,7 +319,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
         return new SerialBlob(binary.getValues());
       }
       return null;
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -338,7 +341,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
         return new SerialBlob(binary.getValues());
       }
       return null;
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -347,7 +350,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public boolean getBoolean(int columnIndex) throws SQLException {
     try {
       return ioTDBRpcDataSet.getBoolean(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -356,7 +359,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public boolean getBoolean(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getBoolean(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -388,7 +391,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
         String s = ioTDBRpcDataSet.getString(columnIndex);
         return s == null ? null : s.getBytes(charset);
       }
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -409,7 +412,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
         String s = ioTDBRpcDataSet.getString(columnName);
         return s == null ? null : s.getBytes(charset);
       }
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -472,7 +475,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
         return ioTDBRpcDataSet.getFloat(columnIndex);
       }
       return getDouble(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -484,7 +487,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
         return ioTDBRpcDataSet.getFloat(columnName);
       }
       return ioTDBRpcDataSet.getDouble(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -519,7 +522,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public float getFloat(int columnIndex) throws SQLException {
     try {
       return ioTDBRpcDataSet.getFloat(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -528,7 +531,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public float getFloat(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getFloat(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -542,7 +545,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public int getInt(int columnIndex) throws SQLException {
     try {
       return ioTDBRpcDataSet.getInt(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -551,7 +554,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public int getInt(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getInt(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -560,7 +563,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public long getLong(int columnIndex) throws SQLException {
     try {
       return ioTDBRpcDataSet.getLong(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -569,7 +572,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public long getLong(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getLong(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -629,7 +632,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public Object getObject(int columnIndex) throws SQLException {
     try {
       return getObject(ioTDBRpcDataSet.findColumnNameByIndex(columnIndex));
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -713,7 +716,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public String getString(int columnIndex) throws SQLException {
     try {
       return ioTDBRpcDataSet.getString(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -748,7 +751,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public Timestamp getTimestamp(int columnIndex) throws SQLException {
     try {
       return ioTDBRpcDataSet.getTimestamp(columnIndex);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -757,7 +760,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   public Timestamp getTimestamp(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getTimestamp(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -1309,7 +1312,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   protected String getValueByName(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getString(columnName);
-    } catch (StatementExecutionException | IllegalArgumentException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
@@ -1317,7 +1320,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
   protected Object getObjectByName(String columnName) throws SQLException {
     try {
       return ioTDBRpcDataSet.getObject(columnName);
-    } catch (StatementExecutionException e) {
+    } catch (StatementExecutionException | IllegalArgumentException | 
IndexOutOfBoundsException e) {
       throw new SQLException(e.getMessage());
     }
   }
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 384a85e228e..203aacdc073 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
@@ -71,6 +71,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
   private String sql;
   private static final String METHOD_NOT_SUPPORTED_STRING = 
JdbcMessages.METHOD_NOT_SUPPORTED;
   private static final Logger logger = 
LoggerFactory.getLogger(IoTDBPreparedStatement.class);
+  private final int parameterCount;
 
   /** save the SQL parameters as (paramLoc,paramValue) pairs. */
   private final Map<Integer, String> parameters = new HashMap<>();
@@ -85,6 +86,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       throws SQLException {
     super(connection, client, sessionId, zoneId, charset);
     this.sql = sql;
+    this.parameterCount = splitSqlStatement(sql).size() - 1;
   }
 
   // Only for tests
@@ -93,6 +95,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       throws SQLException {
     super(connection, client, sessionId, zoneId, TSFileConfig.STRING_CHARSET);
     this.sql = sql;
+    this.parameterCount = splitSqlStatement(sql).size() - 1;
   }
 
   @Override
@@ -130,7 +133,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
     return new ParameterMetaData() {
       @Override
       public int getParameterCount() {
-        return parameters.size();
+        return parameterCount;
       }
 
       @Override
@@ -215,11 +218,21 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
   }
 
   private void checkParameterMetadataIndex(int param) throws SQLException {
-    if (param < 1 || !parameters.containsKey(param)) {
-      throw new SQLException("Parameter index is not set: " + param);
+    checkParameterIndex(param);
+  }
+
+  private void checkParameterIndex(int param) throws SQLException {
+    if (param < 1 || param > parameterCount) {
+      throw new SQLException(
+          "Parameter index out of range: " + param + " (expected 1-" + 
parameterCount + ")");
     }
   }
 
+  private void setParameter(int parameterIndex, String value) throws 
SQLException {
+    checkParameterIndex(parameterIndex);
+    this.parameters.put(parameterIndex, value);
+  }
+
   private String getParameterMetadataValue(int param) throws SQLException {
     checkParameterMetadataIndex(param);
     return parameters.get(param);
@@ -271,7 +284,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       for (byte b : bytes) {
         sb.append(String.format("%02x", b));
       }
-      this.parameters.put(parameterIndex, "X'" + sb.toString() + "'");
+      setParameter(parameterIndex, "X'" + sb.toString() + "'");
     } catch (IOException e) {
       throw new SQLException(Constant.PARAMETER_SUPPORTED);
     }
@@ -299,8 +312,8 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
   }
 
   @Override
-  public void setBoolean(int parameterIndex, boolean x) {
-    this.parameters.put(parameterIndex, Boolean.toString(x));
+  public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+    setParameter(parameterIndex, Boolean.toString(x));
   }
 
   @Override
@@ -315,7 +328,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       return;
     }
     Binary binary = new Binary(x);
-    this.parameters.put(parameterIndex, 
binary.getStringValue(TSFileConfig.STRING_CHARSET));
+    setParameter(parameterIndex, 
binary.getStringValue(TSFileConfig.STRING_CHARSET));
   }
 
   @Override
@@ -357,7 +370,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       return;
     }
     DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
-    this.parameters.put(parameterIndex, "'" + dateFormat.format(x) + "'");
+    setParameter(parameterIndex, "'" + dateFormat.format(x) + "'");
   }
 
   @Override
@@ -366,23 +379,23 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
   }
 
   @Override
-  public void setDouble(int parameterIndex, double x) {
-    this.parameters.put(parameterIndex, Double.toString(x));
+  public void setDouble(int parameterIndex, double x) throws SQLException {
+    setParameter(parameterIndex, Double.toString(x));
   }
 
   @Override
-  public void setFloat(int parameterIndex, float x) {
-    this.parameters.put(parameterIndex, Float.toString(x));
+  public void setFloat(int parameterIndex, float x) throws SQLException {
+    setParameter(parameterIndex, Float.toString(x));
   }
 
   @Override
-  public void setInt(int parameterIndex, int x) {
-    this.parameters.put(parameterIndex, Integer.toString(x));
+  public void setInt(int parameterIndex, int x) throws SQLException {
+    setParameter(parameterIndex, Integer.toString(x));
   }
 
   @Override
-  public void setLong(int parameterIndex, long x) {
-    this.parameters.put(parameterIndex, Long.toString(x));
+  public void setLong(int parameterIndex, long x) throws SQLException {
+    setParameter(parameterIndex, Long.toString(x));
   }
 
   @Override
@@ -418,7 +431,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
 
   @Override
   public void setNull(int parameterIndex, int sqlType) throws SQLException {
-    this.parameters.put(parameterIndex, "NULL");
+    setParameter(parameterIndex, "NULL");
   }
 
   @Override
@@ -945,11 +958,11 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
   }
 
   @Override
-  public void setString(int parameterIndex, String x) {
+  public void setString(int parameterIndex, String x) throws SQLException {
     if (x == null) {
-      this.parameters.put(parameterIndex, null);
+      setParameter(parameterIndex, null);
     } else {
-      this.parameters.put(parameterIndex, "'" + escapeSingleQuotes(x) + "'");
+      setParameter(parameterIndex, "'" + escapeSingleQuotes(x) + "'");
     }
   }
 
@@ -964,6 +977,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       setNull(parameterIndex, Types.TIME);
       return;
     }
+    checkParameterIndex(parameterIndex);
     try {
       long time = x.getTime();
       String timeprecision = client.getProperties().getTimestampPrecision();
@@ -992,6 +1006,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement 
implements PreparedSt
       setNull(parameterIndex, Types.TIME);
       return;
     }
+    checkParameterIndex(parameterIndex);
     try {
       ZonedDateTime zonedDateTime = null;
       long time = x.getTime();
@@ -1015,8 +1030,7 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
       } else {
         zonedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), 
super.zoneId);
       }
-      this.parameters.put(
-          parameterIndex, 
zonedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
+      setParameter(parameterIndex, 
zonedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
     } catch (TException e) {
       logger.error(
           String.format("set time error when iotdb prepared statement :%s ", 
e.getMessage()));
@@ -1031,8 +1045,7 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
     }
     ZonedDateTime zonedDateTime =
         ZonedDateTime.ofInstant(Instant.ofEpochMilli(x.getTime()), 
super.zoneId);
-    this.parameters.put(
-        parameterIndex, 
zonedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
+    setParameter(parameterIndex, 
zonedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
   }
 
   @Override
@@ -1049,8 +1062,7 @@ public class IoTDBPreparedStatement extends 
IoTDBStatement implements PreparedSt
     } else {
       zonedDateTime = 
ZonedDateTime.ofInstant(Instant.ofEpochMilli(x.getTime()), super.zoneId);
     }
-    this.parameters.put(
-        parameterIndex, 
zonedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
+    setParameter(parameterIndex, 
zonedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
   }
 
   @Override
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 998d053fb06..459a4fead14 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
@@ -120,7 +120,7 @@ public class IoTDBTablePreparedStatement extends 
IoTDBStatement implements Prepa
     } else {
       // For non-query statements, only keep text parameters for client-side 
substitution.
       this.serverSidePrepared = false;
-      this.parameterCount = 0;
+      this.parameterCount = splitSqlStatement(sql).size() - 1;
       this.parameterValues = null;
       this.parameterTypes = null;
     }
@@ -525,9 +525,6 @@ public class IoTDBTablePreparedStatement extends 
IoTDBStatement implements Prepa
   }
 
   private void checkParameterIndex(int index) throws SQLException {
-    if (!serverSidePrepared) {
-      return;
-    }
     if (index < 1 || index > parameterCount) {
       throw new SQLException(
           "Parameter index out of range: " + index + " (expected 1-" + 
parameterCount + ")");
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 b9afc39474f..c323fb032bc 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
@@ -192,6 +192,10 @@ public class IoTDBJDBCResultSetTest {
       Assert.assertEquals(2, resultSet.findColumn("root.vehicle.d0.s2"));
       Assert.assertEquals(3, resultSet.findColumn("root.vehicle.d0.s1"));
       Assert.assertEquals(4, resultSet.findColumn("root.vehicle.d0.s0"));
+      Assert.assertThrows(SQLException.class, () -> 
resultSet.findColumn("missing"));
+      Assert.assertThrows(SQLException.class, () -> resultSet.getString(0));
+      Assert.assertThrows(SQLException.class, () -> 
resultSet.getObject("missing"));
+      Assert.assertThrows(SQLException.class, () -> 
resultSet.getTimestamp("missing"));
 
       ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
       // check columnInfoList
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 3d9e8154e8b..9375e032bb6 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
@@ -106,11 +106,16 @@ public class IoTDBPreparedStatementTest {
   @Test
   public void testParameterMetadataRejectsUnsetIndexAndHandlesNullValue() 
throws Exception {
     IoTDBPreparedStatement ps =
-        new IoTDBPreparedStatement(connection, client, sessionId, "SELECT ?", 
zoneId);
+        new IoTDBPreparedStatement(
+            connection, client, sessionId, "SELECT ? FROM root.sg.d WHERE s = 
'?'", zoneId);
     ParameterMetaData metadata = ps.getParameterMetaData();
 
-    assertEquals(0, metadata.getParameterCount());
-    assertThrows(SQLException.class, () -> metadata.getPrecision(1));
+    assertEquals(1, metadata.getParameterCount());
+    assertEquals(0, metadata.getPrecision(1));
+    assertThrows(SQLException.class, () -> metadata.getPrecision(0));
+    assertThrows(SQLException.class, () -> metadata.getParameterMode(2));
+    assertThrows(SQLException.class, () -> ps.setString(0, "x"));
+    assertThrows(SQLException.class, () -> ps.setInt(2, 1));
 
     ps.setString(1, null);
 
@@ -122,13 +127,12 @@ public class IoTDBPreparedStatementTest {
 
   @SuppressWarnings("resource")
   @Test
-  public void unusedArgument() throws SQLException {
+  public void invalidParameterIndex() throws SQLException {
     String sql =
         "SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 
24 and time > 2017-11-1 0:13:00";
     IoTDBPreparedStatement ps =
         new IoTDBPreparedStatement(connection, client, sessionId, sql, zoneId);
-    ps.setString(1, "123");
-    assertFalse(ps.execute());
+    assertThrows(SQLException.class, () -> ps.setString(1, "123"));
   }
 
   @SuppressWarnings("resource")
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 f3422a01638..166587eab86 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
@@ -153,6 +153,8 @@ public class IoTDBTablePreparedStatementTest {
     assertEquals(1, metadata.getParameterCount());
     assertThrows(SQLException.class, () -> metadata.getParameterType(0));
     assertThrows(SQLException.class, () -> metadata.isSigned(2));
+    assertThrows(SQLException.class, () -> ps.setInt(0, 1));
+    assertThrows(SQLException.class, () -> ps.setInt(2, 1));
 
     ps.setInt(1, 1);
 
@@ -331,6 +333,10 @@ public class IoTDBTablePreparedStatementTest {
     IoTDBTablePreparedStatement ps =
         new IoTDBTablePreparedStatement(connection, client, sessionId, sql, 
zoneId);
 
+    assertEquals(1, ps.getParameterMetaData().getParameterCount());
+    assertThrows(SQLException.class, () -> ps.setString(0, null));
+    assertThrows(SQLException.class, () -> ps.setString(2, null));
+
     ps.setString(1, null);
     ps.execute();
 

Reply via email to