Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
电商架构修炼
TDengine
提交
44a51efb
TDengine
项目概览
电商架构修炼
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
44a51efb
编写于
1月 21, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
50558edb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
131 addition
and
0 deletion
+131
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/App3.java
...ctor/jdbc/src/test/java/com/taosdata/jdbc/cases/App3.java
+62
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TdEngineSuperDataGen.java
...st/java/com/taosdata/jdbc/cases/TdEngineSuperDataGen.java
+69
-0
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/App3.java
0 → 100755
浏览文件 @
44a51efb
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
();
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TdEngineSuperDataGen.java
0 → 100755
浏览文件 @
44a51efb
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录