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 2eb265222d4 Reject closed JDBC unsupported operations
2eb265222d4 is described below
commit 2eb265222d443e9178f75ab389a2885122db19af
Author: Caideyipi <[email protected]>
AuthorDate: Tue Jun 9 17:29:09 2026 +0800
Reject closed JDBC unsupported operations
---
.../org/apache/iotdb/jdbc/IoTDBConnection.java | 9 +
.../org/apache/iotdb/jdbc/IoTDBJDBCResultSet.java | 299 +++++++++++----------
.../apache/iotdb/jdbc/IoTDBPreparedStatement.java | 79 +++---
.../java/org/apache/iotdb/jdbc/IoTDBStatement.java | 42 +--
.../iotdb/jdbc/IoTDBTablePreparedStatement.java | 63 +++--
.../org/apache/iotdb/jdbc/IoTDBConnectionTest.java | 12 +
.../apache/iotdb/jdbc/IoTDBJDBCResultSetTest.java | 7 +
.../iotdb/jdbc/IoTDBPreparedStatementTest.java | 8 +
.../org/apache/iotdb/jdbc/IoTDBStatementTest.java | 10 +
.../jdbc/IoTDBTablePreparedStatementTest.java | 8 +
10 files changed, 312 insertions(+), 225 deletions(-)
diff --git
a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
index 25a141e73c6..58e155ef432 100644
--- a/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
+++ b/iotdb-client/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
@@ -318,6 +318,7 @@ public class IoTDBConnection implements Connection {
@Override
public void setClientInfo(Properties arg0) throws SQLClientInfoException {
+ checkOpenForClientInfo("setClientInfo");
throw new SQLClientInfoException(JdbcMessages.NOT_SUPPORT_SET_CLIENT_INFO,
null);
}
@@ -534,6 +535,7 @@ public class IoTDBConnection implements Connection {
@Override
public void setClientInfo(String name, String value) throws
SQLClientInfoException {
+ checkOpenForClientInfo("setClientInfo");
if ("time_zone".equalsIgnoreCase(name)) {
try {
setTimeZone(value);
@@ -770,4 +772,11 @@ public class IoTDBConnection implements Connection {
throw new
SQLException(String.format(JdbcMessages.CANNOT_AFTER_CONNECTION_CLOSED,
action));
}
}
+
+ private void checkOpenForClientInfo(String action) throws
SQLClientInfoException {
+ if (isClosed) {
+ throw new SQLClientInfoException(
+ String.format(JdbcMessages.CANNOT_AFTER_CONNECTION_CLOSED, action),
null);
+ }
+ }
}
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 99b856e446b..d41366b677f 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
@@ -193,22 +193,22 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public boolean absolute(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void afterLast() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void beforeFirst() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void cancelRowUpdates() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -219,6 +219,9 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public void close() throws SQLException {
+ if (explicitlyClosed) {
+ return;
+ }
try {
ioTDBRpcDataSet.close();
explicitlyClosed = true;
@@ -231,7 +234,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public void deleteRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -245,27 +248,27 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public boolean first() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Array getArray(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Array getArray(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getAsciiStream(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getAsciiStream(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -310,12 +313,12 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public InputStream getBinaryStream(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getBinaryStream(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -386,12 +389,12 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public byte getByte(int columnIndex) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public byte getByte(String columnName) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -441,22 +444,22 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public Reader getCharacterStream(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Reader getCharacterStream(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Clob getClob(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Clob getClob(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -467,7 +470,7 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public String getCursorName() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -483,12 +486,12 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public Date getDate(int arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Date getDate(String arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -637,32 +640,32 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public Reader getNCharacterStream(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Reader getNCharacterStream(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public NClob getNClob(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public NClob getNClob(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public String getNString(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public String getNString(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -683,67 +686,67 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public Object getObject(int arg0, Map<String, Class<?>> arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Object getObject(String arg0, Map<String, Class<?>> arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public <T> T getObject(int arg0, Class<T> arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public <T> T getObject(String arg0, Class<T> arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Ref getRef(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Ref getRef(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public int getRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public RowId getRowId(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public RowId getRowId(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public SQLXML getSQLXML(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public SQLXML getSQLXML(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public short getShort(int columnIndex) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public short getShort(String columnName) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -781,12 +784,12 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public Time getTime(int arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Time getTime(String arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -811,12 +814,12 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public Timestamp getTimestamp(int arg0, Calendar arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public Timestamp getTimestamp(String arg0, Calendar arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -827,22 +830,22 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public URL getURL(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public URL getURL(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getUnicodeStream(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public InputStream getUnicodeStream(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -853,17 +856,17 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public void insertRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean isAfterLast() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean isBeforeFirst() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
@@ -877,33 +880,39 @@ public class IoTDBJDBCResultSet implements ResultSet {
}
}
+ private SQLException unsupportedOperation() throws SQLException {
+ checkOpen();
+ return new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ }
+
@Override
public boolean isFirst() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean isLast() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean last() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void moveToCurrentRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void moveToInsertRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean next() throws SQLException {
+ checkOpen();
try {
return ioTDBRpcDataSet.next();
} catch (StatementExecutionException | IoTDBConnectionException e) {
@@ -913,447 +922,447 @@ public class IoTDBJDBCResultSet implements ResultSet {
@Override
public boolean previous() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void refreshRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean relative(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean rowDeleted() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean rowInserted() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public boolean rowUpdated() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateArray(int arg0, Array arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateArray(String arg0, Array arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateAsciiStream(int arg0, InputStream arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateAsciiStream(String arg0, InputStream arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateAsciiStream(int arg0, InputStream arg1, int arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateAsciiStream(String arg0, InputStream arg1, int arg2)
throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateAsciiStream(int arg0, InputStream arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateAsciiStream(String arg0, InputStream arg1, long arg2)
throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBigDecimal(int arg0, BigDecimal arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBigDecimal(String arg0, BigDecimal arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBinaryStream(int arg0, InputStream arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBinaryStream(String arg0, InputStream arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBinaryStream(int arg0, InputStream arg1, int arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBinaryStream(String arg0, InputStream arg1, int arg2)
throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBinaryStream(int arg0, InputStream arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBinaryStream(String arg0, InputStream arg1, long arg2)
throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBlob(int arg0, Blob arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBlob(String arg0, Blob arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBlob(int arg0, InputStream arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBlob(String arg0, InputStream arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBlob(int arg0, InputStream arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBlob(String arg0, InputStream arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBoolean(int arg0, boolean arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBoolean(String arg0, boolean arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateByte(int arg0, byte arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateByte(String arg0, byte arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBytes(int arg0, byte[] arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateBytes(String arg0, byte[] arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateCharacterStream(int arg0, Reader arg1) throws SQLException
{
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateCharacterStream(String arg0, Reader arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateCharacterStream(int arg0, Reader arg1, int arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateCharacterStream(String arg0, Reader arg1, int arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateCharacterStream(int arg0, Reader arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateCharacterStream(String arg0, Reader arg1, long arg2)
throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateClob(int arg0, Clob arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateClob(String arg0, Clob arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateClob(int arg0, Reader arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateClob(String arg0, Reader arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateClob(int arg0, Reader arg1, long arg2) throws SQLException
{
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateClob(String arg0, Reader arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateDate(int arg0, Date arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateDate(String arg0, Date arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateDouble(int arg0, double arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateDouble(String arg0, double arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateFloat(int arg0, float arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateFloat(String arg0, float arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateInt(int arg0, int arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateInt(String arg0, int arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateLong(int arg0, long arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateLong(String arg0, long arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNCharacterStream(int arg0, Reader arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNCharacterStream(String arg0, Reader arg1) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNCharacterStream(int arg0, Reader arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNCharacterStream(String arg0, Reader arg1, long arg2)
throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNClob(int arg0, NClob arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNClob(String arg0, NClob arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNClob(int arg0, Reader arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNClob(String arg0, Reader arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNClob(int arg0, Reader arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNClob(String arg0, Reader arg1, long arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNString(int arg0, String arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNString(String arg0, String arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNull(int arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateNull(String arg0) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateObject(int arg0, Object arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateObject(String arg0, Object arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateObject(int arg0, Object arg1, int arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateObject(String arg0, Object arg1, int arg2) throws
SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateRef(int arg0, Ref arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateRef(String arg0, Ref arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateRow() throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateRowId(int arg0, RowId arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateRowId(String arg0, RowId arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateSQLXML(int arg0, SQLXML arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateSQLXML(String arg0, SQLXML arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateShort(int arg0, short arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateShort(String arg0, short arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateString(int arg0, String arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateString(String arg0, String arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateTime(int arg0, Time arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateTime(String arg0, Time arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateTimestamp(int arg0, Timestamp arg1) throws SQLException {
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
public void updateTimestamp(String arg0, Timestamp arg1) throws SQLException
{
- throw new SQLException(Constant.METHOD_NOT_SUPPORTED);
+ throw unsupportedOperation();
}
@Override
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 91d218dc0ad..46ef522a6e8 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
@@ -237,6 +237,12 @@ public class IoTDBPreparedStatement extends IoTDBStatement
implements PreparedSt
checkParameterIndexRange(param);
}
+ private SQLException unsupportedParameterOperation(int param, String message)
+ throws SQLException {
+ checkConnection("set parameter");
+ return new SQLException(message);
+ }
+
private void checkParameterIndexRange(int param) throws SQLException {
if (param < 1 || param > parameterCount) {
throw new SQLException(
@@ -256,32 +262,32 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
@Override
public void setArray(int parameterIndex, Array x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, int length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -303,29 +309,29 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
}
setParameter(parameterIndex, "X'" + sb.toString() + "'");
} catch (IOException e) {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x, long length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -335,7 +341,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement
implements PreparedSt
@Override
public void setByte(int parameterIndex, byte x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -351,34 +357,34 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
@Override
public void setCharacterStream(int parameterIndex, Reader reader) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, long
length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setClob(int parameterIndex, Clob x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setClob(int parameterIndex, Reader reader) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setClob(int parameterIndex, Reader reader, long length) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -394,7 +400,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement
implements PreparedSt
@Override
public void setDate(int parameterIndex, Date x, Calendar cal) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -419,33 +425,33 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
@Override
public void setNCharacterStream(int parameterIndex, Reader value) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value, long
length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNClob(int parameterIndex, NClob value) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNClob(int parameterIndex, Reader reader, long length) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNString(int parameterIndex, String value) throws SQLException
{
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -455,11 +461,13 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
@Override
public void setNull(int parameterIndex, int sqlType, String typeName) throws
SQLException {
+ checkConnection("set parameter");
throw new SQLException(Constant.PARAMETER_NOT_NULL);
}
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
+ checkConnection("set parameter");
if (x == null) {
setNull(parameterIndex, Types.NULL);
} else if (x instanceof String) {
@@ -509,6 +517,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement
implements PreparedSt
@Override
public void setObject(int parameterIndex, Object parameterObj, int
targetSqlType, int scale)
throws SQLException {
+ checkConnection("set parameter");
if (parameterObj == null) {
setNull(parameterIndex, java.sql.Types.OTHER);
} else {
@@ -580,7 +589,7 @@ public class IoTDBPreparedStatement extends IoTDBStatement
implements PreparedSt
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BLOB:
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
case Types.DATE:
case Types.TIMESTAMP:
java.util.Date parameterAsDate;
@@ -634,14 +643,14 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
break;
case Types.OTHER:
- throw new SQLException(Constant.PARAMETER_SUPPORTED); //
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED); //
default:
- throw new SQLException(Constant.PARAMETER_SUPPORTED); //
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED); //
}
} catch (SQLException ex) {
throw ex;
} catch (Exception ex) {
- throw new SQLException(Constant.PARAMETER_SUPPORTED); //
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED); //
}
}
}
@@ -958,22 +967,22 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setRowId(int parameterIndex, RowId x) throws SQLException {
- throw new SQLException(METHOD_NOT_SUPPORTED_STRING);
+ throw unsupportedParameterOperation(parameterIndex,
METHOD_NOT_SUPPORTED_STRING);
}
@Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws
SQLException {
- throw new SQLException(METHOD_NOT_SUPPORTED_STRING);
+ throw unsupportedParameterOperation(parameterIndex,
METHOD_NOT_SUPPORTED_STRING);
}
@Override
public void setShort(int parameterIndex, short x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -1088,12 +1097,12 @@ public class IoTDBPreparedStatement extends
IoTDBStatement implements PreparedSt
@Override
public void setURL(int parameterIndex, URL x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setUnicodeStream(int parameterIndex, InputStream x, int length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
private String createCompleteSql(final String sql, Map<Integer, String>
parameters)
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 e77eb4577a9..297c19497a9 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
@@ -266,7 +266,7 @@ public class IoTDBStatement implements Statement {
@Override
public void closeOnCompletion() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_CLOSE_ON_COMPLETION);
+ throw unsupportedOperation("closeOnCompletion",
JdbcMessages.NOT_SUPPORT_CLOSE_ON_COMPLETION);
}
/**
@@ -296,17 +296,17 @@ public class IoTDBStatement implements Statement {
@Override
public boolean execute(String arg0, int arg1) throws SQLException {
- throw new SQLException(NOT_SUPPORT_EXECUTE);
+ throw unsupportedOperation("execute", NOT_SUPPORT_EXECUTE);
}
@Override
public boolean execute(String arg0, int[] arg1) throws SQLException {
- throw new SQLException(NOT_SUPPORT_EXECUTE);
+ throw unsupportedOperation("execute", NOT_SUPPORT_EXECUTE);
}
@Override
public boolean execute(String arg0, String[] arg1) throws SQLException {
- throw new SQLException(NOT_SUPPORT_EXECUTE);
+ throw unsupportedOperation("execute", NOT_SUPPORT_EXECUTE);
}
private interface TFunction<T> {
@@ -564,17 +564,17 @@ public class IoTDBStatement implements Statement {
@Override
public int executeUpdate(String arg0, int arg1) throws SQLException {
- throw new SQLException(NOT_SUPPORT_EXECUTE_UPDATE);
+ throw unsupportedOperation("executeUpdate", NOT_SUPPORT_EXECUTE_UPDATE);
}
@Override
public int executeUpdate(String arg0, int[] arg1) throws SQLException {
- throw new SQLException(NOT_SUPPORT_EXECUTE_UPDATE);
+ throw unsupportedOperation("executeUpdate", NOT_SUPPORT_EXECUTE_UPDATE);
}
@Override
public int executeUpdate(String arg0, String[] arg1) throws SQLException {
- throw new SQLException(NOT_SUPPORT_EXECUTE_UPDATE);
+ throw unsupportedOperation("executeUpdate", NOT_SUPPORT_EXECUTE_UPDATE);
}
private int executeUpdateSQL(final String sql)
@@ -632,17 +632,17 @@ public class IoTDBStatement implements Statement {
@Override
public ResultSet getGeneratedKeys() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_GET_GENERATED_KEYS);
+ throw unsupportedOperation("getGeneratedKeys",
JdbcMessages.NOT_SUPPORT_GET_GENERATED_KEYS);
}
@Override
public int getMaxFieldSize() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_GET_MAX_FIELD_SIZE);
+ throw unsupportedOperation("getMaxFieldSize",
JdbcMessages.NOT_SUPPORT_GET_MAX_FIELD_SIZE);
}
@Override
public void setMaxFieldSize(int arg0) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_GET_MAX_FIELD_SIZE);
+ throw unsupportedOperation("setMaxFieldSize",
JdbcMessages.NOT_SUPPORT_GET_MAX_FIELD_SIZE);
}
@Override
@@ -668,7 +668,7 @@ public class IoTDBStatement implements Statement {
@Override
public boolean getMoreResults(int arg0) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_GET_MORE_RESULTS);
+ throw unsupportedOperation("getMoreResults",
JdbcMessages.NOT_SUPPORT_GET_MORE_RESULTS);
}
@Override
@@ -695,7 +695,8 @@ public class IoTDBStatement implements Statement {
@Override
public int getResultSetConcurrency() throws SQLException {
- throw new
SQLException(JdbcMessages.NOT_SUPPORT_GET_RESULT_SET_CONCURRENCY);
+ throw unsupportedOperation(
+ "getResultSetConcurrency",
JdbcMessages.NOT_SUPPORT_GET_RESULT_SET_CONCURRENCY);
}
@Override
@@ -724,7 +725,8 @@ public class IoTDBStatement implements Statement {
@Override
public boolean isCloseOnCompletion() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_IS_CLOSE_ON_COMPLETION);
+ throw unsupportedOperation(
+ "isCloseOnCompletion",
JdbcMessages.NOT_SUPPORT_IS_CLOSE_ON_COMPLETION);
}
@Override
@@ -734,22 +736,23 @@ public class IoTDBStatement implements Statement {
@Override
public boolean isPoolable() throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_IS_POOLABLE);
+ throw unsupportedOperation("isPoolable",
JdbcMessages.NOT_SUPPORT_IS_POOLABLE);
}
@Override
public void setPoolable(boolean arg0) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_POOLABLE);
+ throw unsupportedOperation("setPoolable",
JdbcMessages.NOT_SUPPORT_SET_POOLABLE);
}
@Override
public void setCursorName(String arg0) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_CURSOR_NAME);
+ throw unsupportedOperation("setCursorName",
JdbcMessages.NOT_SUPPORT_SET_CURSOR_NAME);
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
- throw new SQLException(JdbcMessages.NOT_SUPPORT_SET_ESCAPE_PROCESSING);
+ throw unsupportedOperation(
+ "setEscapeProcessing", JdbcMessages.NOT_SUPPORT_SET_ESCAPE_PROCESSING);
}
protected void checkConnection(String action) throws SQLException {
@@ -761,6 +764,11 @@ public class IoTDBStatement implements Statement {
}
}
+ private SQLException unsupportedOperation(String action, String message)
throws SQLException {
+ checkConnection(action);
+ return new SQLException(message);
+ }
+
private boolean reInit() throws SQLException {
this.client = connection.getClient();
this.sessionId = connection.getSessionId();
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 e23d4d49cd7..8003952ca59 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
@@ -493,6 +493,7 @@ public class IoTDBTablePreparedStatement extends
IoTDBStatement implements Prepa
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
+ checkConnection("set parameter");
if (x == null) {
setNull(parameterIndex, Types.NULL);
} else if (x instanceof String) {
@@ -539,6 +540,12 @@ public class IoTDBTablePreparedStatement extends
IoTDBStatement implements Prepa
checkParameterIndexRange(index);
}
+ private SQLException unsupportedParameterOperation(int index, String message)
+ throws SQLException {
+ checkConnection("set parameter");
+ return new SQLException(message);
+ }
+
private void checkParameterMetadataIndex(int index) throws SQLException {
checkConnection("getParameterMetaData");
checkParameterIndexRange(index);
@@ -565,32 +572,32 @@ public class IoTDBTablePreparedStatement extends
IoTDBStatement implements Prepa
@Override
public void setArray(int parameterIndex, Array x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, int length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBinaryStream(int parameterIndex, InputStream x) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
@@ -613,106 +620,106 @@ public class IoTDBTablePreparedStatement extends
IoTDBStatement implements Prepa
@Override
public void setBinaryStream(int parameterIndex, InputStream x, long length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBlob(int parameterIndex, Blob x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setByte(int parameterIndex, byte x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, long
length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setClob(int parameterIndex, Clob x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setClob(int parameterIndex, Reader reader) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setClob(int parameterIndex, Reader reader, long length) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNCharacterStream(int parameterIndex, Reader value, long
length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNClob(int parameterIndex, NClob value) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNClob(int parameterIndex, Reader reader, long length) throws
SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setNString(int parameterIndex, String value) throws SQLException
{
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setRef(int parameterIndex, Ref x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setRowId(int parameterIndex, RowId x) throws SQLException {
- throw new SQLException(METHOD_NOT_SUPPORTED_STRING);
+ throw unsupportedParameterOperation(parameterIndex,
METHOD_NOT_SUPPORTED_STRING);
}
@Override
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws
SQLException {
- throw new SQLException(METHOD_NOT_SUPPORTED_STRING);
+ throw unsupportedParameterOperation(parameterIndex,
METHOD_NOT_SUPPORTED_STRING);
}
@Override
@@ -722,12 +729,12 @@ public class IoTDBTablePreparedStatement extends
IoTDBStatement implements Prepa
@Override
public void setURL(int parameterIndex, URL x) throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
@Override
public void setUnicodeStream(int parameterIndex, InputStream x, int length)
throws SQLException {
- throw new SQLException(Constant.PARAMETER_SUPPORTED);
+ throw unsupportedParameterOperation(parameterIndex,
Constant.PARAMETER_SUPPORTED);
}
// ================== Helper Methods for Backward Compatibility
==================
diff --git
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
index f0d55e1a51d..77fde2f6151 100644
---
a/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
+++
b/iotdb-client/jdbc/src/test/java/org/apache/iotdb/jdbc/IoTDBConnectionTest.java
@@ -43,6 +43,7 @@ import java.sql.Savepoint;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -91,6 +92,7 @@ public class IoTDBConnectionTest {
@Test
public void testSetTimeZoneByClientInfo() throws TException,
SQLClientInfoException {
+ openConnection(connection);
String timeZone = "+07:00";
assertNotEquals(connection.getTimeZone(), timeZone);
when(client.setTimeZone(any(TSSetTimeZoneReq.class))).thenReturn(new
TSStatus(successStatus));
@@ -109,6 +111,7 @@ public class IoTDBConnectionTest {
@Test
public void testSetClientInfoWrapsInvalidTimeZone() {
+ openConnection(connection);
SQLClientInfoException exception =
assertThrows(
SQLClientInfoException.class,
@@ -119,6 +122,7 @@ public class IoTDBConnectionTest {
@Test
public void testSetClientInfoRejectsNullNameWithoutNpe() {
+ openConnection(connection);
assertThrows(SQLClientInfoException.class, () ->
connection.setClientInfo(null, "value"));
}
@@ -271,6 +275,14 @@ public class IoTDBConnectionTest {
assertThrows(SQLException.class, () -> connection.setCatalog("root"));
assertThrows(SQLException.class, () -> connection.getClientInfo());
assertThrows(SQLException.class, () ->
connection.getClientInfo("time_zone"));
+ SQLClientInfoException clientInfoException =
+ assertThrows(
+ SQLClientInfoException.class, () ->
connection.setClientInfo("time_zone", "+07:00"));
+ assertTrue(clientInfoException.getMessage().contains("connection has been
closed"));
+ clientInfoException =
+ assertThrows(
+ SQLClientInfoException.class, () -> connection.setClientInfo(new
Properties()));
+ assertTrue(clientInfoException.getMessage().contains("connection has been
closed"));
assertThrows(SQLException.class, () -> connection.getHoldability());
assertThrows(
SQLException.class, () ->
connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT));
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 5c85c471017..46e620d2734 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
@@ -316,6 +316,13 @@ public class IoTDBJDBCResultSetTest {
Assert.assertThrows(SQLException.class, () -> resultSet.getType());
Assert.assertThrows(SQLException.class, () -> resultSet.getWarnings());
Assert.assertThrows(SQLException.class, () -> resultSet.wasNull());
+
+ SQLException unsupportedException =
+ Assert.assertThrows(SQLException.class, () -> resultSet.absolute(1));
+ Assert.assertEquals("ResultSet has been closed",
unsupportedException.getMessage());
+ unsupportedException =
+ Assert.assertThrows(SQLException.class, () ->
resultSet.updateString(1, "x"));
+ Assert.assertEquals("ResultSet has been closed",
unsupportedException.getMessage());
}
@SuppressWarnings("resource")
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 80781c2e7dd..9e94cefeaab 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
@@ -157,6 +157,14 @@ public class IoTDBPreparedStatementTest {
assertThrows(SQLException.class, () ->
metadata.unwrap(ParameterMetaData.class));
assertThrows(SQLException.class, () -> metadata.getParameterCount());
assertThrows(SQLException.class, () -> metadata.getPrecision(1));
+
+ SQLException unsupportedException =
+ assertThrows(SQLException.class, () -> ps.setArray(1, null));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
+ unsupportedException = assertThrows(SQLException.class, () ->
ps.setRowId(1, null));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
+ unsupportedException = assertThrows(SQLException.class, () ->
ps.setObject(1, new Object()));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
}
@SuppressWarnings("resource")
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 a5cad7a79d8..892a3365157 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
@@ -157,6 +157,16 @@ public class IoTDBStatementTest {
assertThrows(SQLException.class, () -> statement.unwrap(Statement.class));
assertThrows(SQLException.class, () -> statement.getFetchSize());
assertThrows(SQLException.class, () -> statement.getWarnings());
+
+ SQLException unsupportedException =
+ assertThrows(
+ SQLException.class,
+ () -> statement.execute("select 1",
Statement.RETURN_GENERATED_KEYS));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
+ unsupportedException = assertThrows(SQLException.class, () ->
statement.getGeneratedKeys());
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
+ unsupportedException = assertThrows(SQLException.class,
statement::closeOnCompletion);
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
}
@Test(expected = SQLException.class)
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 91c86b4c390..c8c620b0a61 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
@@ -186,6 +186,14 @@ public class IoTDBTablePreparedStatementTest {
assertThrows(SQLException.class, () ->
metadata.unwrap(ParameterMetaData.class));
assertThrows(SQLException.class, () -> metadata.getParameterCount());
assertThrows(SQLException.class, () -> metadata.getParameterType(1));
+
+ SQLException unsupportedException =
+ assertThrows(SQLException.class, () -> ps.setArray(1, null));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
+ unsupportedException = assertThrows(SQLException.class, () ->
ps.setRowId(1, null));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
+ unsupportedException = assertThrows(SQLException.class, () ->
ps.setObject(1, new Object()));
+ assertTrue(unsupportedException.getMessage().contains("statement has been
closed"));
}
@SuppressWarnings("resource")