diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java index bb621bd1308e18d7d404fcc7b53e9fa07d487d73..1b0045ff519f39944f8d15e7a2b5e4ee3566d6ba 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractConnection.java @@ -436,7 +436,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti @Override public void setClientInfo(String name, String value) throws SQLClientInfoException { if (isClosed) - throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); + throw (SQLClientInfoException) TSDBError.createSQLException(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED); if (clientInfoProps == null) clientInfoProps = new Properties(); @@ -446,7 +446,8 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti @Override public void setClientInfo(Properties properties) throws SQLClientInfoException { if (isClosed) - throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); + throw (SQLClientInfoException) TSDBError.createSQLException(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED); + for (Enumeration enumer = properties.keys(); enumer.hasMoreElements(); ) { String name = (String) enumer.nextElement(); @@ -457,7 +458,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti @Override public String getClientInfo(String name) throws SQLException { if (isClosed) - throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); return clientInfoProps.getProperty(name); } @@ -465,7 +466,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti @Override public Properties getClientInfo() throws SQLException { if (isClosed) - throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); return clientInfoProps; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java index c1aff55a6f2e98981540a3833643655a5f12d911..d937f5182593743537b60efa7534d028357288d6 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java @@ -23,6 +23,7 @@ public class TSDBError { TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "parameter index out of range"); + TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED, "connection already closed"); /**************************************************/ TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error"); @@ -48,24 +49,24 @@ public class TSDBError { } public static SQLException createSQLException(int errorNumber, String message) { - if (message == null || message.isEmpty()) { + if (message == null || message.isEmpty() || message.replaceAll("\\s", "").isEmpty()) { if (TSDBErrorNumbers.contains(errorNumber)) message = TSDBErrorMap.get(errorNumber); else message = TSDBErrorMap.get(TSDBErrorNumbers.ERROR_UNKNOWN); } - + // throw SQLFeatureNotSupportedException if (errorNumber == TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD) - return new SQLFeatureNotSupportedException(message); + return new SQLFeatureNotSupportedException(message, "", errorNumber); + // throw SQLClientInfoException + if (errorNumber == TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED) + return new SQLClientInfoException(message,null); if (errorNumber < TSDBErrorNumbers.ERROR_UNKNOWN) // JDBC exception's error number is less than 0x2350 - return new SQLException("ERROR (" + Integer.toHexString(errorNumber) + "): " + message); + return new SQLException("ERROR (" + Integer.toHexString(errorNumber) + "): " + message, "", errorNumber); // JNI exception's error number is large than 0x2350 - return new SQLException("TDengine ERROR (" + Integer.toHexString(errorNumber) + "): " + message); + return new SQLException("TDengine ERROR (" + Integer.toHexString(errorNumber) + "): " + message, "", errorNumber); } - public static SQLClientInfoException createSQLClientInfoException(int errorNumber) { - return new SQLClientInfoException(); - } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java index 85fcd513a74a659bc3a48839df1fdc8553fd355e..5b6dbbdc1852176437aedb4da143eb2a214328cb 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java @@ -17,6 +17,7 @@ public class TSDBErrorNumbers { public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x2311; //not a valid sql for executeUpdate: (SQL) public static final int ERROR_INVALID_FOR_EXECUTE = 0x2312; //not a valid sql for execute: (SQL) public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x2313; // parameter index out of range + public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x2314; // connection already closed public static final int ERROR_UNKNOWN = 0x2350; //unknown error @@ -47,6 +48,7 @@ public class TSDBErrorNumbers { errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_UPDATE); errorNumbers.add(ERROR_INVALID_FOR_EXECUTE); errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE); + errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED); /*****************************************************/ errorNumbers.add(ERROR_SUBSCRIBE_FAILED); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index c847b151d476a98c850d7adfb79ca0ee97605c2f..996ea4a185d97b2294ac06cacccd08862de2de94 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -21,9 +21,6 @@ import java.sql.SQLException; public class TSDBStatement extends AbstractStatement { private TSDBJNIConnector connector; - /** - * To store batched commands - */ /** * Status of current statement */