metas = TDengine.FetchFields(res);
+ for (int j = 0; j < metas.Count; j++)
+ {
+ TDengineMeta meta = (TDengineMeta)metas[j];
+ // Console.WriteLine("index:" + j + ", type:" + meta.type + ", typename:" + meta.TypeName() + ", name:" + meta.name + ", size:" + meta.size);
+ }
+
+ IntPtr rowdata;
+ StringBuilder builder = new StringBuilder();
+ while ((rowdata = TDengine.FetchRows(res)) != IntPtr.Zero)
+ {
+ queryRows++;
+ for (int fields = 0; fields < fieldCount; ++fields)
+ {
+ TDengineMeta meta = metas[fields];
+ int offset = IntPtr.Size * fields;
+ IntPtr data = Marshal.ReadIntPtr(rowdata, offset);
+
+ builder.Append("---");
+
+ if (data == IntPtr.Zero)
+ {
+ builder.Append("NULL");
+ continue;
+ }
+
+ switch ((TDengineDataType)meta.type)
+ {
+ case TDengineDataType.TSDB_DATA_TYPE_BOOL:
+ bool v1 = Marshal.ReadByte(data) == 0 ? false : true;
+ builder.Append(v1);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_TINYINT:
+ byte v2 = Marshal.ReadByte(data);
+ builder.Append(v2);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_SMALLINT:
+ short v3 = Marshal.ReadInt16(data);
+ builder.Append(v3);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_INT:
+ int v4 = Marshal.ReadInt32(data);
+ builder.Append(v4);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_BIGINT:
+ long v5 = Marshal.ReadInt64(data);
+ builder.Append(v5);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_FLOAT:
+ float v6 = (float)Marshal.PtrToStructure(data, typeof(float));
+ builder.Append(v6);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_DOUBLE:
+ double v7 = (double)Marshal.PtrToStructure(data, typeof(double));
+ builder.Append(v7);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_BINARY:
+ string v8 = Marshal.PtrToStringAnsi(data);
+ builder.Append(v8);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_TIMESTAMP:
+ long v9 = Marshal.ReadInt64(data);
+ builder.Append(v9);
+ break;
+ case TDengineDataType.TSDB_DATA_TYPE_NCHAR:
+ string v10 = Marshal.PtrToStringAnsi(data);
+ builder.Append(v10);
+ break;
+ }
+ }
+ builder.Append("---");
+
+ if (queryRows <= 10)
+ {
+ Console.WriteLine(builder.ToString());
+ }
+ builder.Clear();
+ }
+
+ if (TDengine.ErrorNo(res) != 0)
+ {
+ Console.Write("Query is not complete, Error {0:G}",
+ TDengine.ErrorNo(res), TDengine.Error(res));
+ }
+
+ TDengine.FreeResult(res);
+ }
+ /*
+ System.DateTime end = new System.DateTime();
+ TimeSpan ts = end - start;
+
+ Console.Write("Total {0:G} rows inserted, {1:G} rows query, time spend {2:G} seconds.\n"
+ , this.rowsInserted, queryRows, ts.TotalSeconds);
+ */
+ }
+
+ public void CloseConnection()
+ {
+ if (this.conn != IntPtr.Zero)
+ {
+ TDengine.Close(this.conn);
+ }
+ }
+
+ // Main entry
+ static void Main(string[] args)
+ {
+ PrintHelp(args);
+
+ TDengineTest tester = new TDengineTest();
+ tester.ReadArgument(args);
+
+ tester.InitTDengine();
+ tester.ConnectTDengine();
+
+ if (tester.isInsertOnly == false)
+ {
+ tester.dropDatabase();
+ tester.CreateDb();
+
+
+ if (tester.useStable == true)
+ {
+ tester.CreateStable();
+ }
+
+ tester.CreateTablesByThreads();
+ }
+
+ Stopwatch watch = Stopwatch.StartNew();
+ tester.InsertByThreads();
+ watch.Stop();
+ double elapsedMs = watch.Elapsed.TotalMilliseconds;
+
+ Console.WriteLine("Spent {0} seconds to insert {1} records with {2} record(s) per request: {3} records/second",
+ elapsedMs / 1000,
+ tester.recordsPerTable * tester.numOfTables,
+ tester.batchRows,
+ (tester.recordsPerTable * tester.numOfTables * 1000) / elapsedMs);
+
+ tester.ExecuteQuery();
+ tester.CloseConnection();
+
+ Console.WriteLine("End.");
+ }
+
+ public class InsertDataThread
+ {
+ public long id { set; get; }
+ public long start { set; get; }
+ public long end { set; get; }
+ public string dbName { set; get; }
+ public IntPtr conn { set; get; }
+ public string tablePrefix { set; get; }
+ // public string stableName { set; get; }
+ public long recordsPerTable { set; get; }
+ public long batchRows { set; get; }
+ public long numOfTables { set; get; }
+ public bool verbose { set; get; }
+
+ private void DebugPrintFormat(string format, params object[] parameters)
+ {
+ if (verbose == true)
+ {
+ Console.Write(format, parameters);
+ }
+ }
+
+ private void DebugPrint(string str)
+ {
+ if (verbose == true)
+ {
+ Console.Write(str);
+ }
+ }
+
+ public void ThreadMain()
+ {
+ DebugPrintFormat("InsertDataThread {0} from {1} to {2}\n", id, start, end);
+ StringBuilder sql = new StringBuilder();
+
+ DateTime now = DateTime.Now;
+ int h = now.Hour;
+ int m = now.Minute;
+ int s = now.Second;
+
+ long baseTimestamp = 1609430400000; // 2021/01/01 0:0:0
+ DebugPrintFormat("beginTime is {0} + {1}h:{2}m:{3}s\n", baseTimestamp, h, m, s);
+ long beginTimestamp = baseTimestamp + ((h*60 + m) * 60 + s) * 1000;
+
+ long rowsInserted = 0;
+
+ // System.DateTime startTime = new System.DateTime();
+ long i = 0;
+ while (i < recordsPerTable)
+ {
+ for (long table = start; table <= end; ++table)
+ {
+ long inserted = i;
+
+ sql.Clear();
+ sql.Append("INSERT INTO ").
+ Append(this.dbName).Append(".").Append(this.tablePrefix).Append(table).
+ Append(" VALUES");
+ if (recordsPerTable < batchRows)
+ {
+ batchRows = recordsPerTable;
+ }
+ for (int batch = 0; batch < batchRows; ++batch)
+ {
+ sql.Append("(")
+ .Append(beginTimestamp + i + batch)
+ .Append(", 1, 2, 3,")
+ .Append(i + batch)
+ .Append(", 5, 6, 7, 'abc', 'def')");
+
+ }
+ IntPtr res = TDengine.Query(this.conn, sql.ToString());
+ if (res == IntPtr.Zero)
+ {
+ DebugPrint(sql.ToString() + " failure, reason: " + TDengine.Error(res) + "\n");
+ }
+
+ inserted += this.batchRows;
+
+ int affectRows = TDengine.AffectRows(res);
+ rowsInserted += affectRows;
+
+ TDengine.FreeResult(res);
+ if (table == end)
+ {
+ i = inserted;
+ }
+ }
+ }
+
+ }
+ }
+
+ public class CreateTableThread
+ {
+ public long id { set; get; }
+ public long start { set; get; }
+ public long end { set; get; }
+ public string dbName { set; get; }
+ public IntPtr conn { set; get; }
+ public string tablePrefix { set; get; }
+ public string stableName { set; get; }
+ public bool verbose { set; get; }
+ public bool useStable { set; get; }
+
+ private void DebugPrintFormat(string format, params object[] parameters)
+ {
+ if (verbose == true)
+ {
+ Console.Write(format, parameters);
+ }
+ }
+
+ private void DebugPrint(string str)
+ {
+ if (verbose == true)
+ {
+ Console.Write(str);
+ }
+ }
+
+ public void ThreadMain()
+ {
+ DebugPrintFormat("CreateTable {0} from {1} to {2}\n", id, start, end);
+
+ StringBuilder sql = new StringBuilder();
+
+ for (long tableId = start; tableId <= end; tableId++)
+ {
+ sql.Clear();
+ sql = sql.Append("CREATE TABLE IF NOT EXISTS ").
+ Append(this.dbName).Append(".").Append(this.tablePrefix).Append(tableId);
+ if (useStable == true)
+ {
+ sql = sql.Append(" USING ").Append(this.dbName).Append(".").Append(this.stableName).
+ Append(" TAGS(").Append(tableId).Append(")");
+ }
+ else
+ {
+ sql = sql.Append("(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 float, v7 double, v8 binary(10), v9 nchar(10))");
+ }
+ IntPtr res = TDengine.Query(this.conn, sql.ToString());
+ if (res != IntPtr.Zero)
+ {
+ DebugPrint(sql.ToString() + " success\n");
+ }
+ else
+ {
+ DebugPrint(sql.ToString() + " failure, reason: " + TDengine.Error(res) + "\n");
+ ExitProgram();
+ }
+ TDengine.FreeResult(res);
+ }
+
+ }
+ }
+ }
+}
diff --git a/tests/examples/JDBC/JDBCDemo/pom.xml b/tests/examples/JDBC/JDBCDemo/pom.xml
index 98f908b77e8d3bfa03eebf8560205b0424720f1f..d075fc8f2ad480535075b79efc15c55d9bb799a5 100644
--- a/tests/examples/JDBC/JDBCDemo/pom.xml
+++ b/tests/examples/JDBC/JDBCDemo/pom.xml
@@ -5,17 +5,12 @@
4.0.0
com.taosdata.jdbc
- jdbcChecker
+ JDBCDemo
SNAPSHOT
jar
+
-
- org.apache.maven.plugins
- maven-assembly-plugin
- 3.0.0
-
-
org.apache.maven.plugins
maven-assembly-plugin
@@ -23,7 +18,7 @@
- com.taosdata.example.JdbcChecker
+ com.taosdata.example.JDBCDemo
@@ -49,6 +44,7 @@
8
+
@@ -56,18 +52,8 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.12
-
-
- log4j
- log4j
- 1.2.17
-
-
- junit
- junit
- 4.13.1
- test
+ 2.0.15
+
diff --git a/tests/examples/JDBC/JDBCDemo/readme.md b/tests/examples/JDBC/JDBCDemo/readme.md
index e348e458fe938c4f2381c448f3c15e60af27040e..da638a0bcc485cb3d73f75b59348ec260cc871d2 100644
--- a/tests/examples/JDBC/JDBCDemo/readme.md
+++ b/tests/examples/JDBC/JDBCDemo/readme.md
@@ -1,29 +1,37 @@
-# How to Run the JDBC Demo Code On A Linux OS
+# How to Run the JDBC Demo Code On Linux OS
TDengine's JDBC demo project is organized in a Maven way so that users can easily compile, package and run the project. If you don't have Maven on your server, you may install it using
-sudo apt-get install maven
+```
+sudo apt-get install maven
+```
## Install TDengine Client
Make sure you have already installed a tdengine client on your current develop environment.
Download the tdengine package on our website: ``https://www.taosdata.com/cn/all-downloads/`` and install the client.
-## How to run jdbcChecker
-mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JdbcChecker" -Dexec.args="-host localhost"
-
-## How to run jdbcTaosDemo
+## Run jdbcDemo using mvn plugin
run command:
- mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.jdbcTaosdemo.JdbcTaosdemo"
+```
+mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JdbcDemo"
+```
+
and run with your customed args
-mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.jdbcTaosdemo.JdbcTaosdemo" -Dexec.args="-host localhost"
+```
+mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JdbcDemo" -Dexec.args="-host [HOSTNAME]"
+```
## Compile the Demo Code and Run It
+To compile taos-jdbcdriver, go to the source directory ``TDengine/src/connector/jdbc`` and execute
+```
+mvn clean package -Dmaven.test.skip=true
+```
To compile the demo project, go to the source directory ``TDengine/tests/examples/JDBC/JDBCDemo`` and execute
-
-
+```
mvn clean package assembly:single
-
+```
-The ``pom.xml`` is configured to package all the dependencies into one executable jar file.
+To run JDBCDemo.jar, go to ``TDengine/tests/examples/JDBC/JDBCDemo`` and execute
+```
+java -Djava.ext.dirs=../../../../src/connector/jdbc/target:$JAVA_HOME/jre/lib/ext -jar target/JDBCDemo-SNAPSHOT-jar-with-dependencies.jar -host [HOSTNAME]
+```
-To run it, go to ``examples/JDBC/JDBCDemo/target`` and execute
-java -jar jdbcChecker-SNAPSHOT-jar-with-dependencies.jar -host localhost
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcChecker.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java
similarity index 59%
rename from tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcChecker.java
rename to tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java
index 4be71c52214c348ed7b41c3e763de0d908514907..e569de10cf7894aa04fc3cb5bdb8354b581d5a93 100644
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcChecker.java
+++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java
@@ -1,56 +1,77 @@
package com.taosdata.example;
-import com.taosdata.jdbc.TSDBDriver;
-
import java.sql.*;
import java.util.Properties;
-public class JdbcChecker {
+public class JDBCDemo {
private static String host;
- private static String dbName = "test";
- private static String tbName = "weather";
+ private static String driverType = "jni";
+ private static final String dbName = "test";
+ private static final String tbName = "weather";
private Connection connection;
- /**
- * get connection
- **/
+ public static void main(String[] args) {
+ for (int i = 0; i < args.length; i++) {
+ if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1)
+ host = args[++i];
+ if ("-driverType".equalsIgnoreCase(args[i]) && i < args.length - 1) {
+ driverType = args[++i];
+ if (!"jni".equalsIgnoreCase(driverType) && !"restful".equalsIgnoreCase(driverType))
+ printHelp();
+ }
+ }
+
+ if (host == null) {
+ printHelp();
+ }
+
+ JDBCDemo demo = new JDBCDemo();
+ demo.init();
+ demo.createDatabase();
+ demo.useDatabase();
+ demo.dropTable();
+ demo.createTable();
+ demo.insert();
+ demo.select();
+ demo.dropTable();
+ demo.close();
+ }
+
private void init() {
+ // get connection
try {
- Class.forName("com.taosdata.jdbc.TSDBDriver");
+ String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
+ if (driverType.equals("restful")) {
+ Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
+ url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
+ } else {
+ 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");
+ properties.setProperty("host", host);
+ properties.setProperty("charset", "UTF-8");
+ properties.setProperty("locale", "en_US.UTF-8");
+ properties.setProperty("timezone", "UTC-8");
System.out.println("get connection starting...");
- connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
+ connection = DriverManager.getConnection(url, properties);
if (connection != null)
System.out.println("[ OK ] Connection established.");
} catch (ClassNotFoundException | SQLException e) {
- throw new RuntimeException("connection failed: " + host);
+ e.printStackTrace();
}
}
- /**
- * create database
- */
private void createDatabase() {
String sql = "create database if not exists " + dbName;
exuete(sql);
}
- /**
- * use database
- */
private void useDatabase() {
String sql = "use " + dbName;
exuete(sql);
}
- /**
- * select
- */
- private void checkSelect() {
+ private void select() {
final String sql = "select * from test.weather";
executeQuery(sql);
}
@@ -79,40 +100,21 @@ public class JdbcChecker {
}
}
- private String formatString(String str) {
- StringBuilder sb = new StringBuilder();
- int blankCnt = (26 - str.length()) / 2;
- for (int j = 0; j < blankCnt; j++)
- sb.append(" ");
- sb.append(str);
- for (int j = 0; j < blankCnt; j++)
- sb.append(" ");
- sb.append("|");
- return sb.toString();
- }
-
-
- /**
- * insert
- */
- private void checkInsert() {
+ private void insert() {
final String sql = "insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)";
exuete(sql);
}
- /**
- * create table
- */
private void createTable() {
final String sql = "create table if not exists " + dbName + "." + tbName + " (ts timestamp, temperature float, humidity int)";
exuete(sql);
}
- private final void printSql(String sql, boolean succeed, long cost) {
+ private void printSql(String sql, boolean succeed, long cost) {
System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
}
- private final void exuete(String sql) {
+ private void exuete(String sql) {
try (Statement statement = connection.createStatement()) {
long start = System.currentTimeMillis();
boolean execute = statement.execute(sql);
@@ -120,7 +122,7 @@ public class JdbcChecker {
printSql(sql, execute, (end - start));
} catch (SQLException e) {
e.printStackTrace();
-
+
}
}
@@ -135,39 +137,15 @@ public class JdbcChecker {
}
}
- private void checkDropTable() {
+ private void dropTable() {
final String sql = "drop table if exists " + dbName + "." + tbName + "";
exuete(sql);
}
- public static void main(String[] args) {
- for (int i = 0; i < args.length; i++) {
- if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) {
- host = args[++i];
- }
- if ("-db".equalsIgnoreCase(args[i]) && i < args.length - 1) {
- dbName = args[++i];
- }
- if ("-t".equalsIgnoreCase(args[i]) && i < args.length - 1) {
- tbName = args[++i];
- }
- }
-
- if (host == null) {
- System.out.println("Usage: java -jar JDBCConnectorChecker.jar -host ");
- return;
- }
-
- JdbcChecker checker = new JdbcChecker();
- checker.init();
- checker.createDatabase();
- checker.useDatabase();
- checker.checkDropTable();
- checker.createTable();
- checker.checkInsert();
- checker.checkSelect();
- checker.checkDropTable();
- checker.close();
+ private static void printHelp() {
+ System.out.println("Usage: java -jar JdbcDemo.jar -host -driverType ");
+ System.exit(0);
}
+
}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
deleted file mode 100644
index 259985ec9f4708b9317575fd97919adcc82d7161..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
+++ /dev/null
@@ -1,357 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo;
-
-import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
-import com.taosdata.example.jdbcTaosdemo.task.CreateTableTask;
-import com.taosdata.example.jdbcTaosdemo.task.InsertTableDatetimeTask;
-import com.taosdata.example.jdbcTaosdemo.task.InsertTableTask;
-import com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory;
-import com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller;
-import com.taosdata.example.jdbcTaosdemo.utils.TimeStampUtil;
-import org.apache.log4j.Logger;
-
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class JdbcTaosdemo {
-
- private static Logger logger = Logger.getLogger(JdbcTaosdemo.class);
- private final JdbcTaosdemoConfig config;
- private Connection connection;
-
- public JdbcTaosdemo(JdbcTaosdemoConfig config) {
- this.config = config;
- }
-
- public static void main(String[] args) {
- // parse config from args
- JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(args);
-
- boolean isHelp = Arrays.asList(args).contains("--help");
- if (isHelp) {
- JdbcTaosdemoConfig.printHelp();
- return;
- }
- if (config.getHost() == null) {
- JdbcTaosdemoConfig.printHelp();
- return;
- }
-
- JdbcTaosdemo taosdemo = new JdbcTaosdemo(config);
- // establish connection
- taosdemo.init();
- // drop database
- taosdemo.dropDatabase();
- // create database
- taosdemo.createDatabase();
- // use db
- taosdemo.useDatabase();
- // create super table
- taosdemo.createSuperTable();
- // create sub tables
- taosdemo.createTableMultiThreads();
-
- boolean infinite = Arrays.asList(args).contains("--infinite");
- if (infinite) {
- logger.info("!!! Infinite Insert Mode Started. !!!");
- taosdemo.insertInfinite();
- } else {
- // insert into table
- taosdemo.insertMultiThreads();
- // select from sub table
- taosdemo.selectFromTableLimit();
- taosdemo.selectCountFromTable();
- taosdemo.selectAvgMinMaxFromTable();
- // select last from
- taosdemo.selectLastFromTable();
- // select from super table
- taosdemo.selectFromSuperTableLimit();
- taosdemo.selectCountFromSuperTable();
- taosdemo.selectAvgMinMaxFromSuperTable();
- //select avg ,max from stb where tag
- taosdemo.selectAvgMinMaxFromSuperTableWhereTag();
- //select last from stb where location = ''
- taosdemo.selectLastFromSuperTableWhere();
- // select group by
- taosdemo.selectGroupBy();
- // select like
- taosdemo.selectLike();
- // select where ts >= ts<=
- taosdemo.selectLastOneHour();
- taosdemo.selectLastOneDay();
- taosdemo.selectLastOneWeek();
- taosdemo.selectLastOneMonth();
- taosdemo.selectLastOneYear();
-
- // drop super table
- if (config.isDeleteTable())
- taosdemo.dropSuperTable();
- taosdemo.close();
- }
- }
-
-
- /**
- * establish the connection
- */
- private void init() {
- try {
- Class.forName("com.taosdata.jdbc.TSDBDriver");
- connection = ConnectionFactory.build(config);
- if (connection != null)
- logger.info("[ OK ] Connection established.");
- } catch (ClassNotFoundException | SQLException e) {
- logger.error(e.getMessage());
- throw new RuntimeException("connection failed: " + config.getHost());
- }
- }
-
- /**
- * create database
- */
- private void createDatabase() {
- String sql = SqlSpeller.createDatabaseSQL(config.getDbName(), config.getKeep(), config.getDays());
- execute(sql);
- }
-
- /**
- * drop database
- */
- private void dropDatabase() {
- String sql = SqlSpeller.dropDatabaseSQL(config.getDbName());
- execute(sql);
- }
-
- /**
- * use database
- */
- private void useDatabase() {
- String sql = SqlSpeller.useDatabaseSQL(config.getDbName());
- execute(sql);
- }
-
- /**
- * create super table
- */
- private void createSuperTable() {
- String sql = SqlSpeller.createSuperTableSQL(config.getStbName());
- execute(sql);
- }
-
- /**
- * create table use super table with multi threads
- */
- private void createTableMultiThreads() {
- try {
- final int tableSize = config.getNumberOfTable() / config.getNumberOfThreads();
- List threads = new ArrayList<>();
- for (int i = 0; i < config.getNumberOfThreads(); i++) {
- Thread thread = new Thread(new CreateTableTask(config, i * tableSize, tableSize), "Thread-" + i);
- threads.add(thread);
- thread.start();
- }
- for (Thread thread : threads) {
- thread.join();
- }
- logger.info("<<< Multi Threads create table finished.");
- } catch (InterruptedException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * insert data infinitely
- */
- private void insertInfinite() {
- try {
- final long startDatetime = TimeStampUtil.datetimeToLong("2005-01-01 00:00:00.000");
- final long finishDatetime = TimeStampUtil.datetimeToLong("2030-01-01 00:00:00.000");
-
- final int tableSize = config.getNumberOfTable() / config.getNumberOfThreads();
- List threads = new ArrayList<>();
- for (int i = 0; i < config.getNumberOfThreads(); i++) {
- Thread thread = new Thread(new InsertTableDatetimeTask(config, i * tableSize, tableSize, startDatetime, finishDatetime), "Thread-" + i);
- threads.add(thread);
- thread.start();
- }
- for (Thread thread : threads) {
- thread.join();
- }
- logger.info("<<< Multi Threads insert table finished.");
- } catch (InterruptedException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-
- private void insertMultiThreads() {
- try {
- final int tableSize = config.getNumberOfTable() / config.getNumberOfThreads();
- final int numberOfRecordsPerTable = config.getNumberOfRecordsPerTable();
- List threads = new ArrayList<>();
- for (int i = 0; i < config.getNumberOfThreads(); i++) {
- Thread thread = new Thread(new InsertTableTask(config, i * tableSize, tableSize, numberOfRecordsPerTable), "Thread-" + i);
- threads.add(thread);
- thread.start();
- }
- for (Thread thread : threads) {
- thread.join();
- }
- logger.info("<<< Multi Threads insert table finished.");
- } catch (InterruptedException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-
- private void selectFromTableLimit() {
- String sql = SqlSpeller.selectFromTableLimitSQL(config.getDbName(), config.getTbPrefix(), 1, 10, 0);
- executeQuery(sql);
- }
-
- private void selectCountFromTable() {
- String sql = SqlSpeller.selectCountFromTableSQL(config.getDbName(), config.getTbPrefix(), 1);
- executeQuery(sql);
- }
-
- private void selectAvgMinMaxFromTable() {
- String sql = SqlSpeller.selectAvgMinMaxFromTableSQL("current", config.getDbName(), config.getTbPrefix(), 1);
- executeQuery(sql);
- }
-
- private void selectLastFromTable() {
- String sql = SqlSpeller.selectLastFromTableSQL(config.getDbName(), config.getTbPrefix(), 1);
- executeQuery(sql);
- }
-
- private void selectFromSuperTableLimit() {
- String sql = SqlSpeller.selectFromSuperTableLimitSQL(config.getDbName(), config.getStbName(), 10, 0);
- executeQuery(sql);
- }
-
- private void selectCountFromSuperTable() {
- String sql = SqlSpeller.selectCountFromSuperTableSQL(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectAvgMinMaxFromSuperTable() {
- String sql = SqlSpeller.selectAvgMinMaxFromSuperTableSQL("current", config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectAvgMinMaxFromSuperTableWhereTag() {
- String sql = SqlSpeller.selectAvgMinMaxFromSuperTableWhere("current", config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLastFromSuperTableWhere() {
- String sql = SqlSpeller.selectLastFromSuperTableWhere("current", config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectGroupBy() {
- String sql = SqlSpeller.selectGroupBy("current", config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLike() {
- String sql = SqlSpeller.selectLike(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLastOneHour() {
- String sql = SqlSpeller.selectLastOneHour(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLastOneDay() {
- String sql = SqlSpeller.selectLastOneDay(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLastOneWeek() {
- String sql = SqlSpeller.selectLastOneWeek(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLastOneMonth() {
- String sql = SqlSpeller.selectLastOneMonth(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
- private void selectLastOneYear() {
- String sql = SqlSpeller.selectLastOneYear(config.getDbName(), config.getStbName());
- executeQuery(sql);
- }
-
-
- private void close() {
- try {
- if (connection != null) {
- this.connection.close();
- logger.info("connection closed.");
- }
- } catch (SQLException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * drop super table
- */
- private void dropSuperTable() {
- String sql = SqlSpeller.dropSuperTableSQL(config.getDbName(), config.getStbName());
- execute(sql);
- }
-
- /**
- * execute sql, use this method when sql is create, alter, drop..
- */
- private void execute(String sql) {
- try (Statement statement = connection.createStatement()) {
- long start = System.currentTimeMillis();
- boolean execute = statement.execute(sql);
- long end = System.currentTimeMillis();
- printSql(sql, execute, (end - start));
- } catch (SQLException e) {
- logger.error("ERROR execute SQL ===> " + sql);
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-
- private static void printSql(String sql, boolean succeed, long cost) {
- System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
- }
-
- private void executeQuery(String sql) {
- try (Statement statement = connection.createStatement()) {
- long start = System.currentTimeMillis();
- ResultSet resultSet = statement.executeQuery(sql);
- long end = System.currentTimeMillis();
- printSql(sql, true, (end - start));
- printResult(resultSet);
- } catch (SQLException e) {
- logger.error("ERROR execute SQL ===> " + sql);
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-
- private static void printResult(ResultSet resultSet) throws SQLException {
- ResultSetMetaData metaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder sb = new StringBuilder();
- for (int i = 1; i <= metaData.getColumnCount(); i++) {
- String columnLabel = metaData.getColumnLabel(i);
- String value = resultSet.getString(i);
- sb.append(columnLabel + ": " + value + "\t");
- }
- System.out.println(sb.toString());
- }
- }
-
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
deleted file mode 100644
index 36745a93941cc690f37d06d9a3662605723bbd2c..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/domain/JdbcTaosdemoConfig.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.domain;
-
-public final class JdbcTaosdemoConfig {
-
- //The host to connect to TDengine. Must insert one
- private String host;
- //The TCP/IP port number to use for the connection. Default is 6030.
- private int port = 6030;
- //The TDengine user name to use when connecting to the server. Default is 'root'
- private String user = "root";
- //The password to use when connecting to the server. Default is 'taosdata'
- private String password = "taosdata";
-
- //Destination database. Default is 'test'
- private String dbName = "test";
- //keep
- private int keep = 36500;
- //days
- private int days = 120;
-
- //Super table Name. Default is 'meters'
- private String stbName = "meters";
- //Table name prefix. Default is 'd'
- private String tbPrefix = "d";
- //The number of tables. Default is 10.
- private int numberOfTable = 10;
- //The number of records per table. Default is 2
- private int numberOfRecordsPerTable = 2;
- //The number of records per request. Default is 100
- private int numberOfRecordsPerRequest = 100;
-
- //The number of threads. Default is 1.
- private int numberOfThreads = 1;
- //Delete data. Default is false
- private boolean deleteTable = false;
-
- public static void printHelp() {
- System.out.println("Usage: java -jar JdbcTaosDemo.jar [OPTION...]");
- System.out.println("-h host The host to connect to TDengine. you must input one");
- System.out.println("-p port The TCP/IP port number to use for the connection. Default is 6030");
- System.out.println("-u user The TDengine user name to use when connecting to the server. Default is 'root'");
- System.out.println("-P password The password to use when connecting to the server.Default is 'taosdata'");
- System.out.println("-d database Destination database. Default is 'test'");
- System.out.println("-m tablePrefix Table prefix name. Default is 'd'");
- System.out.println("-t num_of_tables The number of tables. Default is 10");
- System.out.println("-n num_of_records_per_table The number of records per table. Default is 2");
- System.out.println("-r num_of_records_per_req The number of records per request. Default is 100");
- System.out.println("-T num_of_threads The number of threads. Default is 1");
- System.out.println("-D delete table Delete data methods. Default is false");
- System.out.println("--help Give this help list");
-// System.out.println("--infinite infinite insert mode");
- }
-
- /**
- * parse args from command line
- *
- * @param args command line args
- * @return JdbcTaosdemoConfig
- */
- public JdbcTaosdemoConfig(String[] args) {
- for (int i = 0; i < args.length; i++) {
- if ("-h".equals(args[i]) && i < args.length - 1) {
- host = args[++i];
- }
- if ("-p".equals(args[i]) && i < args.length - 1) {
- port = Integer.parseInt(args[++i]);
- }
- if ("-u".equals(args[i]) && i < args.length - 1) {
- user = args[++i];
- }
- if ("-P".equals(args[i]) && i < args.length - 1) {
- password = args[++i];
- }
- if ("-d".equals(args[i]) && i < args.length - 1) {
- dbName = args[++i];
- }
- if ("-m".equals(args[i]) && i < args.length - 1) {
- tbPrefix = args[++i];
- }
- if ("-t".equals(args[i]) && i < args.length - 1) {
- numberOfTable = Integer.parseInt(args[++i]);
- }
- if ("-n".equals(args[i]) && i < args.length - 1) {
- numberOfRecordsPerTable = Integer.parseInt(args[++i]);
- }
- if ("-r".equals(args[i]) && i < args.length - 1) {
- numberOfRecordsPerRequest = Integer.parseInt(args[++i]);
- }
- if ("-T".equals(args[i]) && i < args.length - 1) {
- numberOfThreads = Integer.parseInt(args[++i]);
- }
- if ("-D".equals(args[i]) && i < args.length - 1) {
- deleteTable = Boolean.parseBoolean(args[++i]);
- }
- }
- }
-
- public String getHost() {
- return host;
- }
-
- public int getPort() {
- return port;
- }
-
- public String getUser() {
- return user;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getDbName() {
- return dbName;
- }
-
- public int getKeep() {
- return keep;
- }
-
- public int getDays() {
- return days;
- }
-
- public String getStbName() {
- return stbName;
- }
-
- public String getTbPrefix() {
- return tbPrefix;
- }
-
- public int getNumberOfTable() {
- return numberOfTable;
- }
-
- public int getNumberOfRecordsPerTable() {
- return numberOfRecordsPerTable;
- }
-
- public int getNumberOfThreads() {
- return numberOfThreads;
- }
-
- public boolean isDeleteTable() {
- return deleteTable;
- }
-
- public int getNumberOfRecordsPerRequest() {
- return numberOfRecordsPerRequest;
- }
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
deleted file mode 100644
index 1da2c8647efe0e9204f1a591ba9431a489c91cb0..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/CreateTableTask.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.task;
-
-import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
-import com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory;
-import com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller;
-import org.apache.log4j.Logger;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-public class CreateTableTask implements Runnable {
-
- private static Logger logger = Logger.getLogger(CreateTableTask.class);
- private final JdbcTaosdemoConfig config;
- private final int startIndex;
- private final int tableNumber;
-
- public CreateTableTask(JdbcTaosdemoConfig config, int startIndex, int tableNumber) {
- this.config = config;
- this.startIndex = startIndex;
- this.tableNumber = tableNumber;
- }
-
- @Override
- public void run() {
- try {
- Connection connection = ConnectionFactory.build(config);
- for (int i = startIndex; i < startIndex + tableNumber; i++) {
- Statement statement = connection.createStatement();
- String sql = SqlSpeller.createTableSQL(i + 1, config.getDbName(), config.getStbName());
- statement.execute(sql);
- statement.close();
- logger.info(">>> " + sql);
- }
- connection.close();
- } catch (SQLException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
deleted file mode 100644
index 4f60c25646573223a9cbfd820c8eb37e4f6f6c8c..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableDatetimeTask.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.task;
-
-import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
-import com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory;
-import com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller;
-import org.apache.log4j.Logger;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-public class InsertTableDatetimeTask implements Runnable {
- private static Logger logger = Logger.getLogger(InsertTableDatetimeTask.class);
-
- private final JdbcTaosdemoConfig config;
- private final int startTableIndex;
- private final int tableNumber;
- private final long startDatetime;
- private final long finishedDatetime;
-
- public InsertTableDatetimeTask(JdbcTaosdemoConfig config, int startTableIndex, int tableNumber, long startDatetime, long finishedDatetime) {
- this.config = config;
- this.startTableIndex = startTableIndex;
- this.tableNumber = tableNumber;
- this.startDatetime = startDatetime;
- this.finishedDatetime = finishedDatetime;
- }
-
- @Override
- public void run() {
- try {
- Connection connection = ConnectionFactory.build(config);
- int valuesCount = config.getNumberOfRecordsPerRequest();
- for (long ts = startDatetime; ts < finishedDatetime; ts += valuesCount) {
- for (int i = startTableIndex; i < startTableIndex + tableNumber; i++) {
- String sql = SqlSpeller.insertBatchSizeRowsSQL(config.getDbName(), config.getTbPrefix(), i + 1, ts, valuesCount);
- Statement statement = connection.createStatement();
- statement.execute(sql);
- statement.close();
- logger.info(Thread.currentThread().getName() + ">>> " + sql);
- }
- }
- connection.close();
- } catch (SQLException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
deleted file mode 100644
index 644de52dd3e75a77c2d635a6f5328f186259096c..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/task/InsertTableTask.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.task;
-
-import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
-import com.taosdata.example.jdbcTaosdemo.utils.ConnectionFactory;
-import com.taosdata.example.jdbcTaosdemo.utils.SqlSpeller;
-import org.apache.log4j.Logger;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.time.Duration;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
-
-public class InsertTableTask implements Runnable {
- private static final Logger logger = Logger.getLogger(InsertTableTask.class);
-
- private final JdbcTaosdemoConfig config;
- private final int startTbIndex;
- private final int tableNumber;
- private final int recordsNumberPerTable;
-
- public InsertTableTask(JdbcTaosdemoConfig config, int startTbIndex, int tableNumber, int recordsNumberPerTable) {
- this.config = config;
- this.startTbIndex = startTbIndex;
- this.tableNumber = tableNumber;
- this.recordsNumberPerTable = recordsNumberPerTable;
- }
-
- @Override
- public void run() {
- try {
- Connection connection = ConnectionFactory.build(config);
- int keep = config.getKeep();
- Instant end = Instant.now();
- Instant start = end.minus(Duration.ofDays(keep - 1));
- long timeGap = ChronoUnit.MILLIS.between(start, end) / (recordsNumberPerTable - 1);
-
- // iterate insert
- for (int j = 0; j < recordsNumberPerTable; j++) {
- long ts = start.toEpochMilli() + (j * timeGap);
- // insert data into echo table
- for (int i = startTbIndex; i < startTbIndex + tableNumber; i++) {
- String sql = SqlSpeller.insertBatchSizeRowsSQL(config.getDbName(), config.getTbPrefix(), i + 1, ts, config.getNumberOfRecordsPerRequest());
- logger.info(Thread.currentThread().getName() + ">>> " + sql);
- Statement statement = connection.createStatement();
- statement.execute(sql);
- statement.close();
- }
- }
- connection.close();
- } catch (SQLException e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
- }
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/ConnectionFactory.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/ConnectionFactory.java
deleted file mode 100644
index 52691f4de722db2eb17e7061e09ff0e59a390077..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/ConnectionFactory.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.utils;
-
-import com.taosdata.example.jdbcTaosdemo.domain.JdbcTaosdemoConfig;
-import com.taosdata.jdbc.TSDBDriver;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-
-public class ConnectionFactory {
-
- public static Connection build(JdbcTaosdemoConfig config) throws SQLException {
- return build(config.getHost(), config.getPort(), config.getDbName(), config.getUser(), config.getPassword());
- }
-
- public static Connection build(String host, int port, String dbName) throws SQLException {
- return build(host, port, dbName, "root", "taosdata");
- }
-
- private static Connection build(String host, int port, String dbName, String user, String password) throws SQLException {
- Properties properties = new Properties();
- properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, user);
- properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, password);
- 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 + ":" + port + "/" + dbName + "", properties);
- }
-
-
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
deleted file mode 100644
index b4a79e9eba47cc947d822b645d0ae1f9952f08f0..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.utils;
-
-import java.util.Random;
-
-public class SqlSpeller {
- private static final Random random = new Random(System.currentTimeMillis());
- private static final String[] locations = {
- "Beijing", "Shanghai", "Guangzhou", "Shenzhen",
- "HangZhou", "Tianjin", "Wuhan", "Changsha", "Nanjing", "Xian"
- };
-
- public static String createDatabaseSQL(String dbName, int keep, int days) {
- return "create database if not exists " + dbName + " keep " + keep + " days " + days;
- }
-
- public static String dropDatabaseSQL(String dbName) {
- return "drop database if exists " + dbName;
- }
-
- public static String useDatabaseSQL(String dbName) {
- return "use " + dbName;
- }
-
- public static String createSuperTableSQL(String superTableName) {
- return "create table if not exists " + superTableName + "(ts timestamp, current float, voltage int, phase float) tags(location binary(64), groupId int)";
- }
-
- public static String dropSuperTableSQL(String dbName, String superTableName) {
- return "drop table if exists " + dbName + "." + superTableName;
- }
-
- public static String createTableSQL(int tableIndex, String dbName, String superTableName) {
- String location = locations[random.nextInt(locations.length)];
- return "create table d" + tableIndex + " using " + dbName + "." + superTableName + " tags('" + location + "'," + tableIndex + ")";
- }
-
- public static String insertOneRowSQL(String dbName, String tbPrefix, int tableIndex, long ts) {
- float current = 10 + random.nextFloat();
- int voltage = 200 + random.nextInt(20);
- float phase = random.nextFloat();
- String sql = "insert into " + dbName + "." + tbPrefix + "" + tableIndex + " " + "values(" + ts + ", " + current + ", " + voltage + ", " + phase + ")";
- return sql;
- }
-
- public static String insertBatchSizeRowsSQL(String dbName, String tbPrefix, int tbIndex, long ts, int valuesCount) {
- float current = 10 + random.nextFloat();
- int voltage = 200 + random.nextInt(20);
- float phase = random.nextFloat();
- StringBuilder sb = new StringBuilder();
- sb.append("insert into " + dbName + "." + tbPrefix + "" + tbIndex + " " + "values");
- for (int i = 0; i < valuesCount; i++) {
- sb.append("(" + (ts + i) + ", " + current + ", " + voltage + ", " + phase + ") ");
- }
- return sb.toString();
- }
-
- public static String selectFromTableLimitSQL(String dbName, String tbPrefix, int tbIndex, int limit, int offset) {
- return "select * from " + dbName + "." + tbPrefix + "" + tbIndex + " limit " + limit + " offset " + offset;
- }
-
- public static String selectCountFromTableSQL(String dbName, String tbPrefix, int tbIndex) {
- return "select count(*) from " + dbName + "." + tbPrefix + "" + tbIndex;
- }
-
- public static String selectAvgMinMaxFromTableSQL(String field, String dbName, String tbPrefix, int tbIndex) {
- return "select avg(" + field + "),min(" + field + "),max(" + field + ") from " + dbName + "." + tbPrefix + "" + tbIndex;
- }
-
- public static String selectFromSuperTableLimitSQL(String dbName, String stbName, int limit, int offset) {
- return "select * from " + dbName + "." + stbName + " limit " + limit + " offset " + offset;
- }
-
- public static String selectCountFromSuperTableSQL(String dbName, String stableName) {
- return "select count(*) from " + dbName + "." + stableName;
- }
-
- public static String selectAvgMinMaxFromSuperTableSQL(String field, String dbName, String stbName) {
- return "select avg(" + field + "),min(" + field + "),max(" + field + ") from " + dbName + "." + stbName + "";
- }
-
- public static String selectLastFromTableSQL(String dbName, String tbPrefix, int tbIndex) {
- return "select last(*) from " + dbName + "." + tbPrefix + "" + tbIndex;
- }
-
- //select avg ,max from stb where tag
- public static String selectAvgMinMaxFromSuperTableWhere(String field, String dbName, String stbName) {
- return "select avg(" + field + "),min(" + field + "),max(" + field + ") from " + dbName + "." + stbName + " where location = '" + locations[random.nextInt(locations.length)] + "'";
- }
-
- //select last from stb where
- public static String selectLastFromSuperTableWhere(String field, String dbName, String stbName) {
- return "select last(" + field + ") from " + dbName + "." + stbName + " where location = '" + locations[random.nextInt(locations.length)] + "'";
- }
-
- public static String selectGroupBy(String field, String dbName, String stbName) {
- return "select avg(" + field + ") from " + dbName + "." + stbName + " group by location";
- }
-
- public static String selectLike(String dbName, String stbName) {
- return "select * from " + dbName + "." + stbName + " where location like 'S%'";
- }
-
- public static String selectLastOneHour(String dbName, String stbName) {
- return "select * from " + dbName + "." + stbName + " where ts >= now - 1h";
- }
-
- public static String selectLastOneDay(String dbName, String stbName) {
- return "select * from " + dbName + "." + stbName + " where ts >= now - 1d";
- }
-
- public static String selectLastOneWeek(String dbName, String stbName) {
- return "select * from " + dbName + "." + stbName + " where ts >= now - 1w";
- }
-
- public static String selectLastOneMonth(String dbName, String stbName) {
- return "select * from " + dbName + "." + stbName + " where ts >= now - 1n";
- }
-
- public static String selectLastOneYear(String dbName, String stbName) {
- return "select * from " + dbName + "." + stbName + " where ts >= now - 1y";
- }
-
- // select group by
- // select like
- // select ts >= ts<=
-}
\ No newline at end of file
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
deleted file mode 100644
index 0a345afdd1e45123d889d7ee198cf8efd201176b..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtil.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.utils;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.Duration;
-import java.time.Instant;
-import java.util.Date;
-
-public class TimeStampUtil {
- private static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss.SSS";
-
- public static long datetimeToLong(String dateTime) {
- SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
- try {
- return sdf.parse(dateTime).getTime();
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static String longToDatetime(long time) {
- SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
- return sdf.format(new Date(time));
- }
-
- public static void main(String[] args) throws ParseException {
-
-// Instant now = Instant.now();
-// System.out.println(now);
-// Instant years20Ago = now.minus(Duration.ofDays(365));
-// System.out.println(years20Ago);
-
-
- }
-
-
-}
diff --git a/tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties b/tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties
deleted file mode 100644
index b445e5f52edf1a2b19c35c1be187716d17cdd7b1..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,21 +0,0 @@
-### 设置###
-log4j.rootLogger=debug,stdout,DebugLog,ErrorLog
-### 输出信息到控制抬 ###
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Target=System.out
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
-### 输出DEBUG 级别以上的日志到=logs/error.log ###
-log4j.appender.DebugLog=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.DebugLog.File=logs/debug.log
-log4j.appender.DebugLog.Append=true
-log4j.appender.DebugLog.Threshold=DEBUG
-log4j.appender.DebugLog.layout=org.apache.log4j.PatternLayout
-log4j.appender.DebugLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
-### 输出ERROR 级别以上的日志到=logs/error.log ###
-log4j.appender.ErrorLog=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.ErrorLog.File=logs/error.log
-log4j.appender.ErrorLog.Append=true
-log4j.appender.ErrorLog.Threshold=ERROR
-log4j.appender.ErrorLog.layout=org.apache.log4j.PatternLayout
-log4j.appender.ErrorLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
\ No newline at end of file
diff --git a/tests/examples/JDBC/JDBCDemo/src/test/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtilTest.java b/tests/examples/JDBC/JDBCDemo/src/test/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtilTest.java
deleted file mode 100644
index f370b2ef6eaa708b061ebf4a7f58f3d31f78f999..0000000000000000000000000000000000000000
--- a/tests/examples/JDBC/JDBCDemo/src/test/java/com/taosdata/example/jdbcTaosdemo/utils/TimeStampUtilTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.taosdata.example.jdbcTaosdemo.utils;
-
-import org.junit.Test;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.time.Duration;
-import java.time.Instant;
-import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
-import java.util.Date;
-
-import static org.junit.Assert.*;
-
-public class TimeStampUtilTest {
-
- @Test
- public void datetimeToLong() {
- final String startTime = "2005-01-01 00:00:00.000";
- long start = TimeStampUtil.datetimeToLong(startTime);
- assertEquals(1104508800000l, start);
- }
-
- @Test
- public void longToDatetime() {
- String datetime = TimeStampUtil.longToDatetime(1510000000000L);
- assertEquals("2017-11-07 04:26:40.000", datetime);
- }
-
- @Test
- public void getStartDateTime() {
- int keep = 365;
-
- Instant end = Instant.now();
- System.out.println(end.toString());
- System.out.println(end.toEpochMilli());
-
- Instant start = end.minus(Duration.ofDays(keep));
- System.out.println(start.toString());
- System.out.println(start.toEpochMilli());
-
- int numberOfRecordsPerTable = 10;
- long timeGap = ChronoUnit.MILLIS.between(start, end) / (numberOfRecordsPerTable - 1);
- System.out.println(timeGap);
-
- System.out.println("===========================");
- for (int i = 0; i < numberOfRecordsPerTable; i++) {
- long ts = start.toEpochMilli() + (i * timeGap);
- System.out.println(i + " : " + ts);
- }
- }
-}
\ No newline at end of file
diff --git a/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java b/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
index 79c0aacea740dcb6fca9780c7f64872c537c3225..4e33b75bc57aa18ebc0cae166e84401d4357d614 100644
--- a/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
+++ b/tests/examples/JDBC/connectionPools/src/main/java/com/taosdata/demo/ConnectionPoolDemo.java
@@ -82,12 +82,27 @@ public class ConnectionPoolDemo {
init(dataSource);
- ExecutorService executor = Executors.newFixedThreadPool(threadCount);
- while (true) {
- executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize));
- if (sleep > 0)
- TimeUnit.MILLISECONDS.sleep(sleep);
+ try {
+ Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement();
+ String sql = "insert into " + dbName + ".t_1 values('2020-01-01 00:00:00.000',12.12,111)";
+ int affectRows = statement.executeUpdate(sql);
+ System.out.println("affectRows >>> " + affectRows);
+ affectRows = statement.executeUpdate(sql);
+ System.out.println("affectRows >>> " + affectRows);
+ statement.close();
+ connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
}
+
+
+// ExecutorService executor = Executors.newFixedThreadPool(threadCount);
+// while (true) {
+// executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize));
+// if (sleep > 0)
+// TimeUnit.MILLISECONDS.sleep(sleep);
+// }
}
private static void init(DataSource dataSource) {
diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication.java
index 69cd3e0ced2888575d890ffea36407455c4bea7a..f693214567fb3e8780e8ee1a867cf765de0ec8d7 100644
--- a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication.java
+++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication.java
@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan(basePackages = {"com.taosdata.jdbc.springbootdemo.dao"})
@SpringBootApplication
-public class SpringbootdemoApplication {
+public class cd {
public static void main(String[] args) {
SpringApplication.run(SpringbootdemoApplication.class, args);
diff --git a/tests/examples/JDBC/taosdemo/pom.xml b/tests/examples/JDBC/taosdemo/pom.xml
index 5cbf6cb7004566e8d6ea6e16e8b70f289ac2941d..15b22917b6103740ac419e046d5fd8fa79363d25 100644
--- a/tests/examples/JDBC/taosdemo/pom.xml
+++ b/tests/examples/JDBC/taosdemo/pom.xml
@@ -2,88 +2,107 @@
4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 2.4.0
-
-
com.taosdata
taosdemo
2.0
taosdemo
+ jar
Demo project for TDengine
- 1.8
+ 5.3.2
-
-
+
- com.taosdata.jdbc
- taos-jdbcdriver
- 2.0.14
+ org.springframework
+ spring-context
+ ${spring.version}
-
- mysql
- mysql-connector-java
- 5.1.47
+ org.springframework
+ spring-core
+ ${spring.version}
-
- com.baomidou
- mybatis-plus-boot-starter
- 3.1.2
+ org.springframework
+ spring-beans
+ ${spring.version}
-
- log4j
- log4j
- 1.2.17
+ org.springframework
+ spring-expression
+ ${spring.version}
+
+
+ org.springframework
+ spring-aop
+ ${spring.version}
+
+
+ org.springframework
+ spring-aspects
+ ${spring.version}
+
+
+ org.springframework
+ spring-test
+ ${spring.version}
+ test
+
+
+ org.springframework
+ spring-jdbc
+ ${spring.version}
-
+
+
+ com.zaxxer
+ HikariCP
+ 3.4.5
+
+
- org.springframework.boot
- spring-boot-starter-jdbc
+ com.taosdata.jdbc
+ taos-jdbcdriver
+ 2.0.15
+ system
+ ${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar
+
- org.springframework.boot
- spring-boot-starter-thymeleaf
+ com.alibaba
+ fastjson
+ 1.2.75
+
- org.springframework.boot
- spring-boot-starter-web
+ mysql
+ mysql-connector-java
+ 5.1.47
+ test
+
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
- 2.1.4
+ log4j
+ log4j
+ 1.2.17
+
junit
junit
4.12
test
-
- org.springframework.boot
- spring-boot-devtools
- runtime
- true
-
+
org.projectlombok
lombok
- true
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
+ 1.18.16
+ provided
@@ -94,6 +113,7 @@
**/*.properties
**/*.xml
+ **/*.jar
true
@@ -108,10 +128,41 @@
- org.springframework.boot
- spring-boot-maven-plugin
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 3.1.0
+
+
+
+
+ com.taosdata.taosdemo.TaosDemoApplication
+
+
+
+ jar-with-dependencies
+
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+