Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冷面1992
TDengine
提交
1734b1d1
TDengine
项目概览
冷面1992
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1734b1d1
编写于
3月 04, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3173]<feature>: java taosdemo can execute one sql statement by commandline
上级
bfeb758b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
85 addition
and
7 deletion
+85
-7
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosDemoApplication.java
+17
-5
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
.../com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
+5
-2
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SqlExecuteor.java
...main/java/com/taosdata/taosdemo/service/SqlExecuteor.java
+36
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/Printer.java
...mo/src/main/java/com/taosdata/taosdemo/utils/Printer.java
+27
-0
未找到文件。
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosDemoApplication.java
浏览文件 @
1734b1d1
...
...
@@ -3,15 +3,17 @@ package com.taosdata.taosdemo;
import
com.taosdata.taosdemo.components.DataSourceFactory
;
import
com.taosdata.taosdemo.components.JdbcTaosdemoConfig
;
import
com.taosdata.taosdemo.domain.SuperTableMeta
;
import
com.taosdata.taosdemo.service.DatabaseService
;
import
com.taosdata.taosdemo.service.QueryService
;
import
com.taosdata.taosdemo.service.SubTableService
;
import
com.taosdata.taosdemo.service.SuperTableService
;
import
com.taosdata.taosdemo.service.*
;
import
com.taosdata.taosdemo.service.data.SuperTableMetaGenerator
;
import
com.taosdata.taosdemo.utils.Printer
;
import
org.apache.log4j.Logger
;
import
javax.sql.DataSource
;
import
java.io.IOException
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.util.Arrays
;
...
...
@@ -32,6 +34,17 @@ public class TaosDemoApplication {
}
// 初始化
final
DataSource
dataSource
=
DataSourceFactory
.
getInstance
(
config
.
host
,
config
.
port
,
config
.
user
,
config
.
password
);
if
(
config
.
executeSql
!=
null
&&
!
config
.
executeSql
.
isEmpty
()
&&
!
config
.
executeSql
.
replaceAll
(
"\\s"
,
""
).
isEmpty
())
{
Thread
task
=
new
Thread
(
new
SqlExecuteor
(
dataSource
,
config
.
executeSql
));
task
.
start
();
try
{
task
.
join
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
;
}
final
DatabaseService
databaseService
=
new
DatabaseService
(
dataSource
);
final
SuperTableService
superTableService
=
new
SuperTableService
(
dataSource
);
final
SubTableService
subTableService
=
new
SubTableService
(
dataSource
);
...
...
@@ -96,7 +109,6 @@ public class TaosDemoApplication {
// 查询
/**********************************************************************************/
// 删除表
if
(
config
.
dropTable
)
{
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/JdbcTaosdemoConfig.java
浏览文件 @
1734b1d1
...
...
@@ -42,7 +42,7 @@ public final class JdbcTaosdemoConfig {
public
int
rate
=
10
;
public
long
range
=
1000
l
;
// select task
public
String
executeSql
;
// drop task
public
boolean
dropTable
=
false
;
...
...
@@ -89,7 +89,7 @@ public final class JdbcTaosdemoConfig {
System
.
out
.
println
(
"-rate The proportion of data out of order. effective only if order is 1. min 0, max 100, default is 10"
);
System
.
out
.
println
(
"-range The range of data out of order. effective only if order is 1. default is 1000 ms"
);
// query task
// System.out.println("-sqlFile The select sql file
");
System
.
out
.
println
(
"-executeSql execute a specific sql.
"
);
// drop task
System
.
out
.
println
(
"-dropTable Drop data before quit. Default is false"
);
System
.
out
.
println
(
"--help Give this help list"
);
...
...
@@ -207,6 +207,9 @@ public final class JdbcTaosdemoConfig {
range
=
Integer
.
parseInt
(
args
[++
i
]);
}
// select task
if
(
"-executeSql"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
executeSql
=
args
[++
i
];
}
// drop task
if
(
"-dropTable"
.
equals
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SqlExecuteor.java
0 → 100644
浏览文件 @
1734b1d1
package
com.taosdata.taosdemo.service
;
import
com.taosdata.taosdemo.utils.Printer
;
import
javax.sql.DataSource
;
import
java.sql.Connection
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
SqlExecuteor
implements
Runnable
{
private
final
DataSource
dataSource
;
private
final
String
sql
;
public
SqlExecuteor
(
DataSource
dataSource
,
String
sql
)
{
this
.
dataSource
=
dataSource
;
this
.
sql
=
sql
;
}
@Override
public
void
run
()
{
try
(
Connection
conn
=
dataSource
.
getConnection
();
Statement
stmt
=
conn
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
boolean
execute
=
stmt
.
execute
(
sql
);
long
end
=
System
.
currentTimeMillis
();
if
(
execute
)
{
ResultSet
rs
=
stmt
.
getResultSet
();
Printer
.
printResult
(
rs
);
}
else
{
Printer
.
printSql
(
sql
,
true
,
(
end
-
start
));
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/utils/Printer.java
0 → 100644
浏览文件 @
1734b1d1
package
com.taosdata.taosdemo.utils
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
public
class
Printer
{
public
static
void
printResult
(
ResultSet
resultSet
)
throws
SQLException
{
ResultSetMetaData
metaData
=
resultSet
.
getMetaData
();
while
(
resultSet
.
next
())
{
for
(
int
i
=
1
;
i
<=
metaData
.
getColumnCount
();
i
++)
{
String
columnLabel
=
metaData
.
getColumnLabel
(
i
);
String
value
=
resultSet
.
getString
(
i
);
System
.
out
.
printf
(
"%s: %s\t"
,
columnLabel
,
value
);
}
System
.
out
.
println
();
}
}
public
static
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
}
private
Printer
()
{
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录