diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml
index b73bb010e06341cbfd473c7356e3cbe88d30139c..766a58f9babe3e4eec8b482b937378be6b8f0943 100755
--- a/src/connector/jdbc/deploy-pom.xml
+++ b/src/connector/jdbc/deploy-pom.xml
@@ -93,14 +93,13 @@
3.6.1
UTF-8
- 11
- 11
+ 8
+ 8
true
true
-
org.apache.maven.plugins
maven-source-plugin
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
index 86d179eae4950edae7fda5b1b979e1f61ea521f2..d8df2fc0d35651f61f3cdcc5f6186711b6bf3cf0 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection.java
@@ -57,9 +57,9 @@ public class TSDBConnection implements Connection {
File cfgDir = loadConfigDir(info.getProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR));
File cfgFile = cfgDir.listFiles((dir, name) -> "taos.cfg".equalsIgnoreCase(name))[0];
List endpoints = loadConfigEndpoints(cfgFile);
- if (!endpoints.isEmpty()){
- info.setProperty(TSDBDriver.PROPERTY_KEY_HOST,endpoints.get(0).split(":")[0]);
- info.setProperty(TSDBDriver.PROPERTY_KEY_PORT,endpoints.get(0).split(":")[1]);
+ if (!endpoints.isEmpty()) {
+ info.setProperty(TSDBDriver.PROPERTY_KEY_HOST, endpoints.get(0).split(":")[0]);
+ info.setProperty(TSDBDriver.PROPERTY_KEY_PORT, endpoints.get(0).split(":")[1]);
}
//load taos.cfg end
@@ -69,15 +69,15 @@ public class TSDBConnection implements Connection {
info.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD));
}
- private List loadConfigEndpoints(File cfgFile){
+ private List loadConfigEndpoints(File cfgFile) {
List endpoints = new ArrayList<>();
- try(BufferedReader reader = new BufferedReader(new FileReader(cfgFile))) {
+ try (BufferedReader reader = new BufferedReader(new FileReader(cfgFile))) {
String line = null;
- while ((line = reader.readLine())!=null){
- if (line.trim().startsWith("firstEp") || line.trim().startsWith("secondEp")){
- endpoints.add(line.substring(line.indexOf('p')+1).trim());
+ while ((line = reader.readLine()) != null) {
+ if (line.trim().startsWith("firstEp") || line.trim().startsWith("secondEp")) {
+ endpoints.add(line.substring(line.indexOf('p') + 1).trim());
}
- if (endpoints.size()>1)
+ if (endpoints.size() > 1)
break;
}
} catch (FileNotFoundException e) {
@@ -91,7 +91,7 @@ public class TSDBConnection implements Connection {
/**
* @param cfgDirPath
* @return return the config dir
- * **/
+ **/
private File loadConfigDir(String cfgDirPath) {
if (cfgDirPath == null)
return loadDefaultConfigDir();
@@ -103,8 +103,8 @@ public class TSDBConnection implements Connection {
/**
* @return search the default config dir, if the config dir is not exist will return null
- * */
- private File loadDefaultConfigDir(){
+ */
+ private File loadDefaultConfigDir() {
File cfgDir;
File cfgDir_linux = new File("/etc/taos");
cfgDir = cfgDir_linux.exists() ? cfgDir_linux : null;
@@ -132,7 +132,9 @@ public class TSDBConnection implements Connection {
public Statement createStatement() throws SQLException {
if (!this.connector.isClosed()) {
- return new TSDBStatement(this.connector);
+ TSDBStatement statement = new TSDBStatement(this, this.connector);
+ statement.setConnection(this);
+ return statement;
} else {
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
}
@@ -153,7 +155,7 @@ public class TSDBConnection implements Connection {
public PreparedStatement prepareStatement(String sql) throws SQLException {
if (!this.connector.isClosed()) {
- return new TSDBPreparedStatement(this.connector, sql);
+ return new TSDBPreparedStatement(this, this.connector, sql);
} else {
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
index 6097ad9c43f517f19c42da94c865a5c1caae65ea..230943fd53ae8fa36b9de40f851a5c263c052f0d 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
@@ -42,8 +42,8 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
private SavedPreparedStatement savedPreparedStatement;
- TSDBPreparedStatement(TSDBJNIConnector connecter, String sql) {
- super(connecter);
+ TSDBPreparedStatement(TSDBConnection connection, TSDBJNIConnector connecter, String sql) {
+ super(connection, connecter);
init(sql);
}
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 06ae4495960c2dff20b5812bd3023b313c8b3533..a8d6ceb713136dd2a25b92de286daac86e01fa09 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
@@ -19,153 +19,164 @@ import java.util.ArrayList;
import java.util.List;
public class TSDBStatement implements Statement {
- private TSDBJNIConnector connecter = null;
+ private TSDBJNIConnector connecter = null;
- /** To store batched commands */
- protected List batchedArgs;
+ /**
+ * To store batched commands
+ */
+ protected List batchedArgs;
- /** Timeout for a query */
- protected int queryTimeout = 0;
+ /**
+ * Timeout for a query
+ */
+ protected int queryTimeout = 0;
- private Long pSql = 0l;
+ private Long pSql = 0l;
/**
* Status of current statement
*/
- private boolean isClosed = true;
- private int affectedRows = 0;
+ private boolean isClosed = true;
+ private int affectedRows = 0;
- TSDBStatement(TSDBJNIConnector connecter) {
- this.connecter = connecter;
- this.isClosed = false;
- }
+ private TSDBConnection connection;
- public T unwrap(Class iface) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public void setConnection(TSDBConnection connection) {
+ this.connection = connection;
+ }
- public boolean isWrapperFor(Class> iface) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ TSDBStatement(TSDBConnection connection, TSDBJNIConnector connecter) {
+ this.connection = connection;
+ this.connecter = connecter;
+ this.isClosed = false;
+ }
- public ResultSet executeQuery(String sql) throws SQLException {
+ public T unwrap(Class iface) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean isWrapperFor(Class> iface) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public ResultSet executeQuery(String sql) throws SQLException {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
// TODO make sure it is not a update query
- pSql = this.connecter.executeQuery(sql);
+ pSql = this.connecter.executeQuery(sql);
- long resultSetPointer = this.connecter.getResultSet();
+ long resultSetPointer = this.connecter.getResultSet();
- if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
- this.connecter.freeResultSet(pSql);
- throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
- }
+ if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
+ this.connecter.freeResultSet(pSql);
+ throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
+ }
// create/insert/update/delete/alter
- if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
- this.connecter.freeResultSet(pSql);
- return null;
- }
+ if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
+ this.connecter.freeResultSet(pSql);
+ return null;
+ }
- if (!this.connecter.isUpdateQuery(pSql)) {
- return new TSDBResultSet(this.connecter, resultSetPointer);
- } else {
- this.connecter.freeResultSet(pSql);
- return null;
- }
+ if (!this.connecter.isUpdateQuery(pSql)) {
+ return new TSDBResultSet(this.connecter, resultSetPointer);
+ } else {
+ this.connecter.freeResultSet(pSql);
+ return null;
+ }
- }
+ }
- public int executeUpdate(String sql) throws SQLException {
+ public int executeUpdate(String sql) throws SQLException {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
// TODO check if current query is update query
- pSql = this.connecter.executeQuery(sql);
- long resultSetPointer = this.connecter.getResultSet();
+ pSql = this.connecter.executeQuery(sql);
+ long resultSetPointer = this.connecter.getResultSet();
- if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
- this.connecter.freeResultSet(pSql);
- throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
- }
+ if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
+ this.connecter.freeResultSet(pSql);
+ throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
+ }
- this.affectedRows = this.connecter.getAffectedRows(pSql);
- this.connecter.freeResultSet(pSql);
+ this.affectedRows = this.connecter.getAffectedRows(pSql);
+ this.connecter.freeResultSet(pSql);
- return this.affectedRows;
- }
+ return this.affectedRows;
+ }
- public String getErrorMsg(long pSql) {
- return this.connecter.getErrMsg(pSql);
- }
+ public String getErrorMsg(long pSql) {
+ return this.connecter.getErrMsg(pSql);
+ }
- public void close() throws SQLException {
+ public void close() throws SQLException {
if (!isClosed) {
if (!this.connecter.isResultsetClosed()) {
this.connecter.freeResultSet();
}
isClosed = true;
}
- }
+ }
- public int getMaxFieldSize() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public int getMaxFieldSize() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public void setMaxFieldSize(int max) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public void setMaxFieldSize(int max) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public int getMaxRows() throws SQLException {
- // always set maxRows to zero, meaning unlimitted rows in a resultSet
- return 0;
- }
+ public int getMaxRows() throws SQLException {
+ // always set maxRows to zero, meaning unlimitted rows in a resultSet
+ return 0;
+ }
- public void setMaxRows(int max) throws SQLException {
- // always set maxRows to zero, meaning unlimitted rows in a resultSet
- }
+ public void setMaxRows(int max) throws SQLException {
+ // always set maxRows to zero, meaning unlimitted rows in a resultSet
+ }
- public void setEscapeProcessing(boolean enable) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public void setEscapeProcessing(boolean enable) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public int getQueryTimeout() throws SQLException {
- return queryTimeout;
- }
+ public int getQueryTimeout() throws SQLException {
+ return queryTimeout;
+ }
- public void setQueryTimeout(int seconds) throws SQLException {
- this.queryTimeout = seconds;
- }
+ public void setQueryTimeout(int seconds) throws SQLException {
+ this.queryTimeout = seconds;
+ }
- public void cancel() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public void cancel() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public SQLWarning getWarnings() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public SQLWarning getWarnings() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public void clearWarnings() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public void clearWarnings() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public void setCursorName(String name) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ public void setCursorName(String name) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
- public boolean execute(String sql) throws SQLException {
+ public boolean execute(String sql) throws SQLException {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
- boolean res = true;
- pSql = this.connecter.executeQuery(sql);
- long resultSetPointer = this.connecter.getResultSet();
+ boolean res = true;
+ pSql = this.connecter.executeQuery(sql);
+ long resultSetPointer = this.connecter.getResultSet();
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
- this.connecter.freeResultSet(pSql);
+ this.connecter.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
// no result set is retrieved
@@ -173,145 +184,147 @@ public class TSDBStatement implements Statement {
res = false;
}
- return res;
- }
+ return res;
+ }
- public ResultSet getResultSet() throws SQLException {
+ public ResultSet getResultSet() throws SQLException {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
- long resultSetPointer = connecter.getResultSet();
- TSDBResultSet resSet = null;
+ long resultSetPointer = connecter.getResultSet();
+ TSDBResultSet resSet = null;
if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
resSet = new TSDBResultSet(connecter, resultSetPointer);
}
- return resSet;
- }
+ return resSet;
+ }
- public int getUpdateCount() throws SQLException {
+ public int getUpdateCount() throws SQLException {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
- return this.affectedRows;
- }
-
- public boolean getMoreResults() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public void setFetchDirection(int direction) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public int getFetchDirection() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- /*
- * used by spark
- */
- public void setFetchSize(int rows) throws SQLException {
- }
-
- /*
- * used by spark
- */
- public int getFetchSize() throws SQLException {
- return 4096;
- }
-
- public int getResultSetConcurrency() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public int getResultSetType() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public void addBatch(String sql) throws SQLException {
- if (batchedArgs == null) {
- batchedArgs = new ArrayList();
- }
- batchedArgs.add(sql);
- }
-
- public void clearBatch() throws SQLException {
- batchedArgs.clear();
- }
-
- public int[] executeBatch() throws SQLException {
+ return this.affectedRows;
+ }
+
+ public boolean getMoreResults() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public void setFetchDirection(int direction) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public int getFetchDirection() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ /*
+ * used by spark
+ */
+ public void setFetchSize(int rows) throws SQLException {
+ }
+
+ /*
+ * used by spark
+ */
+ public int getFetchSize() throws SQLException {
+ return 4096;
+ }
+
+ public int getResultSetConcurrency() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public int getResultSetType() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public void addBatch(String sql) throws SQLException {
+ if (batchedArgs == null) {
+ batchedArgs = new ArrayList();
+ }
+ batchedArgs.add(sql);
+ }
+
+ public void clearBatch() throws SQLException {
+ batchedArgs.clear();
+ }
+
+ public int[] executeBatch() throws SQLException {
if (isClosed) {
throw new SQLException("Invalid method call on a closed statement.");
}
- if (batchedArgs == null) {
- throw new SQLException(TSDBConstants.WrapErrMsg("Batch is empty!"));
- } else {
- int[] res = new int[batchedArgs.size()];
- for (int i = 0; i < batchedArgs.size(); i++) {
- res[i] = executeUpdate(batchedArgs.get(i));
- }
- return res;
- }
- }
-
- public Connection getConnection() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean getMoreResults(int current) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public ResultSet getGeneratedKeys() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public int executeUpdate(String sql, String[] columnNames) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean execute(String sql, int[] columnIndexes) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean execute(String sql, String[] columnNames) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public int getResultSetHoldability() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean isClosed() throws SQLException {
- return isClosed;
- }
-
- public void setPoolable(boolean poolable) throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean isPoolable() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public void closeOnCompletion() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
-
- public boolean isCloseOnCompletion() throws SQLException {
- throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
- }
+ if (batchedArgs == null) {
+ throw new SQLException(TSDBConstants.WrapErrMsg("Batch is empty!"));
+ } else {
+ int[] res = new int[batchedArgs.size()];
+ for (int i = 0; i < batchedArgs.size(); i++) {
+ res[i] = executeUpdate(batchedArgs.get(i));
+ }
+ return res;
+ }
+ }
+
+ public Connection getConnection() throws SQLException {
+ if (this.connecter != null)
+ return this.connection;
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean getMoreResults(int current) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public ResultSet getGeneratedKeys() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public int executeUpdate(String sql, String[] columnNames) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean execute(String sql, String[] columnNames) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public int getResultSetHoldability() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean isClosed() throws SQLException {
+ return isClosed;
+ }
+
+ public void setPoolable(boolean poolable) throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean isPoolable() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public void closeOnCompletion() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
+
+ public boolean isCloseOnCompletion() throws SQLException {
+ throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
+ }
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java
index 7e144cbe0f032b6e675749fce704e171f75f2d94..066dfad5d50fb5fcb31c00a645ccc0487f6a594e 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java
@@ -23,6 +23,7 @@ import java.sql.SQLException;
public class SqlSyntaxValidator {
private TSDBConnection tsdbConnection;
+
public SqlSyntaxValidator(Connection connection) {
this.tsdbConnection = (TSDBConnection) connection;
}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java
index 6c3437186f89ced4374ec6ae302224312c7cb4f2..b793a47c990a930579b749b1eec95abed6ad554e 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java
@@ -8,8 +8,7 @@ import org.junit.BeforeClass;
public class BaseTest {
private static boolean testCluster = false;
- private static TDNodes nodes = new TDNodes();
-
+ private static TDNodes nodes = new TDNodes();
@BeforeClass
public static void setupEnv() {
@@ -19,11 +18,9 @@ public class BaseTest {
nodes.getTDNode(1).setRunning(1);
nodes.stop(1);
}
-
nodes.setTestCluster(testCluster);
nodes.deploy(1);
- nodes.start(1);
-
+ nodes.start(1);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java
index c49293c96b568d70644f548722cf83374c430949..7d96cbb5381d099f7b67ecdb5414093c54b37b65 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java
@@ -7,13 +7,11 @@ import org.junit.Test;
import java.sql.*;
import java.util.Properties;
import java.util.Random;
-
-import static org.junit.Assert.assertEquals;
-import java.util.Properties;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.*;
+import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
public class BatchInsertTest extends BaseTest {
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
index 1844a92b471b8c6faf593de269ca337cc01b2cec..6c75860e0f0a2647175de6e836f7f1aeb62c539a 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java
@@ -34,7 +34,6 @@ public class SelectTest extends BaseTest {
statement.executeUpdate("drop database if exists " + dbName);
statement.executeUpdate("create database if not exists " + dbName);
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
-
}
@Test
@@ -66,6 +65,5 @@ public class SelectTest extends BaseTest {
statement.close();
connection.close();
Thread.sleep(10);
-
}
}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..9608c4985db15312e8e2966badfe4db8241bc306
--- /dev/null
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java
@@ -0,0 +1,108 @@
+package com.taosdata.jdbc.cases;
+
+import com.taosdata.jdbc.lib.TSDBCommon;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+
+public class BatchInsertTest {
+
+ static String host = "localhost";
+ static String dbName = "test";
+ static String stbName = "meters";
+ static int numOfTables = 30;
+ final static int numOfRecordsPerTable = 1000;
+ static long ts = 1496732686000l;
+ final static String tablePrefix = "t";
+
+ private Connection connection;
+
+ @Before
+ public void before() {
+ try {
+ connection = TSDBCommon.getConn(host);
+ TSDBCommon.createDatabase(connection, dbName);
+ TSDBCommon.createStable(connection, stbName);
+ TSDBCommon.createTables(connection, numOfTables, stbName, tablePrefix);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testBatchInsert(){
+ ExecutorService executorService = Executors.newFixedThreadPool(numOfTables);
+ for (int i = 0; i < numOfTables; i++) {
+ final int index = i;
+ executorService.execute(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ long startTime = System.currentTimeMillis();
+ Statement statement = connection.createStatement(); // get statement
+ StringBuilder sb = new StringBuilder();
+ sb.append("INSERT INTO " + tablePrefix + index + " VALUES");
+ Random rand = new Random();
+ for (int j = 1; j <= numOfRecordsPerTable; j++) {
+ sb.append("(" + (ts + j) + ", ");
+ sb.append(rand.nextInt(100) + ", ");
+ sb.append(rand.nextInt(100) + ", ");
+ sb.append(rand.nextInt(100) + ")");
+ }
+ statement.addBatch(sb.toString());
+ statement.executeBatch();
+ long endTime = System.currentTimeMillis();
+ System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds");
+ connection.commit();
+ statement.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ executorService.shutdown();
+ try {
+ executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ try{
+ Statement statement = connection.createStatement();
+ ResultSet rs = statement.executeQuery("select * from meters");
+ int num = 0;
+ while (rs.next()) {
+ num++;
+ }
+ assertEquals(num, numOfTables * numOfRecordsPerTable);
+ rs.close();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void after() {
+ try {
+ if (connection != null)
+ connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java
new file mode 100644
index 0000000000000000000000000000000000000000..0e2613d617074571c86c39ef253d68af9a0f6922
--- /dev/null
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java
@@ -0,0 +1,47 @@
+package com.taosdata.jdbc.lib;
+
+import com.taosdata.jdbc.TSDBDriver;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+public class TSDBCommon {
+
+ public static Connection getConn(String host) throws SQLException, ClassNotFoundException {
+ Class.forName("com.taosdata.jdbc.TSDBDriver");
+ Properties properties = new Properties();
+ properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
+ properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
+ properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
+ properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
+ return DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
+ }
+
+ public static void createDatabase(Connection connection, String dbName) throws SQLException {
+ Statement statement = connection.createStatement();
+ statement.executeUpdate("drop database if exists " + dbName);
+ statement.executeUpdate("create database if not exists " + dbName);
+ statement.executeUpdate("use " + dbName);
+ statement.close();
+ }
+
+ public static void createStable(Connection connection, String stbName) throws SQLException {
+ Statement statement = connection.createStatement();
+ String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))";
+ statement.executeUpdate(createTableSql);
+ statement.close();
+ }
+
+ public static void createTables(Connection connection, int numOfTables, String stbName,String tablePrefix) throws SQLException {
+ Statement statement = connection.createStatement();
+ for(int i = 0; i < numOfTables; i++) {
+ String loc = i % 2 == 0 ? "beijing" : "shanghai";
+ String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')";
+ statement.executeUpdate(createSubTalbesSql);
+ }
+ statement.close();
+ }
+}
diff --git a/tests/examples/JDBC/SpringJdbcTemplate/pom.xml b/tests/examples/JDBC/SpringJdbcTemplate/pom.xml
index b796d52d28fbc641800a889fd3f81bc9c62f9147..15aed1cf03b4e10e5a69e16be99ea2320a24609e 100644
--- a/tests/examples/JDBC/SpringJdbcTemplate/pom.xml
+++ b/tests/examples/JDBC/SpringJdbcTemplate/pom.xml
@@ -1,85 +1,91 @@
- 4.0.0
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
- com.taosdata.jdbc
- SpringJdbcTemplate
- 1.0-SNAPSHOT
+ com.taosdata.jdbc
+ SpringJdbcTemplate
+ 1.0-SNAPSHOT
- SpringJdbcTemplate
- http://www.taosdata.com
+ SpringJdbcTemplate
+ http://www.taosdata.com
-
- UTF-8
- 1.8
- 1.8
-
+
+ UTF-8
+ 1.8
+ 1.8
+
-
+
-
- org.springframework
- spring-context
- 4.3.2.RELEASE
-
+
+ org.springframework
+ spring-context
+ 5.2.8.RELEASE
+
-
- org.springframework
- spring-jdbc
- 4.3.2.RELEASE
-
+
+ org.springframework
+ spring-jdbc
+ 5.1.9.RELEASE
+
-
- junit
- junit
- 4.11
- test
-
+
+ org.springframework
+ spring-test
+ 5.1.9.RELEASE
+
-
- com.taosdata.jdbc
- taos-jdbcdriver
- 2.0.2
-
+
+ junit
+ junit
+ 4.13
+ test
+
-
+
+ com.taosdata.jdbc
+ taos-jdbcdriver
+ 2.0.4
+
-
-
-
- maven-compiler-plugin
- 3.8.0
-
- 1.8
- 1.8
-
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- 3.1.0
-
-
-
- com.taosdata.jdbc.App
-
-
-
- jar-with-dependencies
-
-
-
-
- make-assembly
- package
-
- single
-
-
-
-
-
-
+
+
+
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+ 1.8
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 3.1.0
+
+
+
+ com.taosdata.jdbc.example.jdbcTemplate.App
+
+
+
+ jar-with-dependencies
+
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+
+
+
diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App.java
deleted file mode 100644
index 3230af46a8016fee3d58c89ea3b2c1ddcf39cea5..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.taosdata.jdbc;
-
-
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.util.CollectionUtils;
-
-import java.util.List;
-import java.util.Map;
-
-public class App {
-
- public static void main( String[] args ) {
-
- ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
-
- JdbcTemplate jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate");
-
- // create database
- jdbcTemplate.execute("create database if not exists db ");
-
- // create table
- jdbcTemplate.execute("create table if not exists db.tb (ts timestamp, temperature int, humidity float)");
-
- String insertSql = "insert into db.tb values(now, 23, 10.3) (now + 1s, 20, 9.3)";
-
- // insert rows
- int affectedRows = jdbcTemplate.update(insertSql);
-
- System.out.println("insert success " + affectedRows + " rows.");
-
- // query for list
- List