提交 3b04b871 编写于 作者: Z zyyang

[TD-2822]<fix>: fix invalid result set pointer error

上级 3a2e0297
package com.taosdata.example;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import java.sql.*;
import java.util.Calendar;
import java.util.Properties;
import java.util.Random;
import java.util.UUID;
public class JDBCDemo {
private static String host;
......@@ -9,7 +15,7 @@ public class JDBCDemo {
private static final String tbName = "weather";
private Connection connection;
public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < args.length; i++) {
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1)
host = args[++i];
......@@ -23,12 +29,48 @@ public class JDBCDemo {
demo.useDatabase();
demo.dropTable();
demo.createTable();
demo.insert();
demo.select();
demo.dropTable();
demo.insertBatch();
// demo.insert();
// demo.select();
// demo.dropTable();
demo.close();
}
private void insertBatch() throws InterruptedException {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, -5);
for (int i = 0; i < 100; i++) {
insertSingle();
}
Thread.sleep(1000);
}
private void insertSingle() {
new Thread(() -> {
System.out.println(Thread.currentThread().getName() + "开始插入数据");
String sql = "";
for (int j = 0; j < 1000000; j++) {
String id = UUID.randomUUID().toString().replace("-", "");
Calendar calendar = Calendar.getInstance();
for (int i = 0; i < 10000; i++) {
if (i % 500 == 0 && StringUtils.isNotEmpty(sql)) {
sql = "INSERT INTO base_" + id + " USING " + tbName + " TAGS ('" + id + "') VALUES" + sql;
exuete(sql);
sql = "";
} else {
calendar.add(Calendar.MINUTE, -new Random().nextInt(10));
String format = DateFormatUtils.format(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
sql += " ('" + format + "', " + new Random().nextDouble() * 10000 + ")";
}
}
System.out.println(Thread.currentThread().getName() + ",第" + j + "个参数:" + id + "完成10000条写入");
}
System.out.println(Thread.currentThread().getName() + "插入完毕");
}).start();
}
private void init() {
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
// get connection
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册