提交 44a51efb 编写于 作者: Z zyyang

change

上级 50558edb
package com.taosdata.jdbc.cases;
import org.apache.commons.dbcp2.BasicDataSource;
import java.sql.*;
public class App3 {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// 添加数据源1-TDengine,并且作为schema命名为“public”
String url = "jdbc:TAOS://127.0.0.1:6030/hdb";
Class.forName("com.taosdata.jdbc.TSDBDriver");
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl(url);
dataSource.setUsername("root");
dataSource.setPassword("taosdata");
// 执行SQL语句,sql语句中表的引用必须用前面设置的schema名称,例如“testdata”就是schema“public“下的表,”datedim“是schema”test“下的表。
String sql = "select cast(s.updates as date ),t.id,t.cmt from public.testdata t , test.datedim s "
+ "where cast(t.uptime as date )=s.updates and t.uptime<'2011-12-01 00:00:00' and t.id>100 limit 100 offset 10 ";
long startTime = System.currentTimeMillis();
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
// ResultSet rs = stmt.executeQuery(sql);
long rowCount = 0;
String[] types = { "TABLE" };
ResultSet rs = conn.getMetaData().getTables("hdb", null, null, types);
while (rs.next()) {
// if (rowCount < 5) {
for (int j = 0; j < rs.getMetaData().getColumnCount(); j++) {
System.out.print(rs.getMetaData().getColumnName(j + 1) + ": " + rs.getObject(j) + ", ");
}
System.out.println();
// }
rowCount++;
}
rs.close();
System.out.println("\nGET COLUMN:");
rs = conn.getMetaData().getColumns("hdb", null, "sdata", null);
while (rs.next()) {
// if (rowCount < 5) {
ResultSetMetaData meta = rs.getMetaData();
for (int j = 0; j < rs.getMetaData().getColumnCount(); j++) {
if (j != 7) {
System.out.print(rs.getMetaData().getColumnName(j + 1) + ": " + rs.getObject(j) + ", ");
System.out.println();
}
}
System.out.println();
// }
rowCount++;
}
long endTime = System.currentTimeMillis();
System.out.println("execute time:" + (endTime - startTime) + "ms, resultset rows " + rowCount + ", "
+ rowCount * 1000 / (endTime - startTime) + " rows/sec");
rs.close();
stmt.close();
conn.close();
}
}
package com.taosdata.jdbc.cases;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import org.apache.commons.codec.digest.DigestUtils;
public class TdEngineSuperDataGen {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("com.taosdata.jdbc.TSDBDriver");
String url = "jdbc:TAOS://127.0.0.1:6030/test?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
// create database
stmt.executeUpdate("create database if not exists hdb");
// use database
stmt.executeUpdate("use hdb");
stmt.executeUpdate("drop table if exists sdata");
// create table
stmt.executeUpdate(
"create table if not exists sdata (uptime timestamp, id int, x int , y int ,cmt binary(100)) tags(location nchar(100),tname nchar(100))");
ZoneId zoneId = ZoneId.systemDefault();
Map<String, String> table = new HashMap<>();
table.put("dt001", "beijing");
table.put("dt002", "shanghai");
table.put("dt003", "chongqing");
table.put("dt004", "xian");
for (Entry<String, String> kv : table.entrySet()) {
LocalDateTime d = LocalDateTime.now().minusMonths(2);
long rowCount = LocalDateTime.now().atZone(zoneId).toEpochSecond() - d.atZone(zoneId).toEpochSecond();
Random r = new Random();
StringBuilder sb = null;
long startTime = System.currentTimeMillis();
try {
for (long i = 0; i < rowCount; i++) {
sb = new StringBuilder("insert into " + kv.getKey() + " using sdata tags(" + kv.getValue() + ","
+ kv.getKey() + ") values('");
d = d.plusSeconds(1);
sb.append(d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.MS")));
sb.append("'," + i + "," + r.nextInt(100) + "," + r.nextInt(100) + ",'");
sb.append(DigestUtils.md5Hex(d.toString()));
sb.append("')");
stmt.executeUpdate(sb.toString());
}
} catch (SQLException e) {
System.out.println(d);
System.out.println(sb.toString());
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println("generate data execute time:" + (endTime - startTime) + "ms, resultset rows " + rowCount
+ ", " + rowCount * 1000 / (endTime - startTime) + " rows/sec");
}
stmt.close();
conn.close();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册