Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bd838288
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bd838288
编写于
11月 10, 2021
作者:
P
Ping Xiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add jdbc batchinsert demo
上级
00c762cb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
88 addition
and
1 deletion
+88
-1
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+1
-1
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/BatchInsert.java
...CDemo/src/main/java/com/taosdata/example/BatchInsert.java
+87
-0
未找到文件。
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
bd838288
...
...
@@ -17,7 +17,7 @@
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.3
4
</version>
<version>
2.0.3
5
</version>
</dependency>
</dependencies>
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/BatchInsert.java
0 → 100644
浏览文件 @
bd838288
package
com.taosdata.example
;
import
java.sql.*
;
import
java.util.*
;
public
class
BatchInsert
{
private
static
final
String
host
=
"127.0.0.1"
;
private
static
final
String
user
=
"root"
;
private
static
final
String
password
=
"taosdata"
;
private
static
final
String
dbname
=
"test"
;
private
static
final
String
stbname
=
"stb"
;
private
static
final
int
tables
=
100
;
private
static
final
int
rows
=
500
;
private
static
final
long
ts
=
1604877767000
l
;
private
Connection
conn
;
private
void
init
()
{
// final String url = "jdbc:TAOS://" + host + ":6030/?user=" + user + "&password=" + password;
final
String
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user="
+
user
+
"&password="
+
password
;
// get connection
try
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"locale"
,
"en_US.UTF-8"
);
properties
.
setProperty
(
"timezone"
,
"UTC-8"
);
System
.
out
.
println
(
"get connection starting..."
);
conn
=
DriverManager
.
getConnection
(
url
,
properties
);
if
(
conn
!=
null
){
System
.
out
.
println
(
"[ OK ] Connection established."
);
}
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"drop database if exists "
+
dbname
);
stmt
.
execute
(
"create database if not exists "
+
dbname
);
stmt
.
execute
(
"use "
+
dbname
);
stmt
.
execute
(
"create table "
+
dbname
+
"."
+
stbname
+
"(ts timestamp, col int) tags(id int)"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
String
generateSql
()
{
StringBuilder
sb
=
new
StringBuilder
();
Random
rand
=
new
Random
();
sb
.
append
(
"insert into "
);
for
(
int
i
=
0
;
i
<
tables
;
i
++)
{
sb
.
append
(
dbname
+
".tb"
+
i
+
" using "
+
dbname
+
"."
+
stbname
+
" tags("
+
i
+
") values"
);
for
(
int
j
=
0
;
j
<
rows
;
j
++)
{
sb
.
append
(
"("
);
sb
.
append
(
ts
+
j
);
sb
.
append
(
","
);
sb
.
append
(
rand
.
nextInt
(
1000
));
sb
.
append
(
") "
);
}
}
return
sb
.
toString
();
}
private
void
executeQuery
(
String
sql
)
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
stmt
.
execute
(
sql
);
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"insert "
+
tables
*
rows
+
" records, cost "
+
(
end
-
start
)+
"ms"
);
}
catch
(
SQLException
ex
)
{
ex
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
)
{
BatchInsert
bi
=
new
BatchInsert
();
String
sql
=
bi
.
generateSql
();
bi
.
init
();
bi
.
executeQuery
(
sql
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录