Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_44632607
TDengine
提交
babe8f15
T
TDengine
项目概览
weixin_44632607
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
babe8f15
编写于
9月 25, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
9月 25, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3682 from taosdata/feature/TD-1572
update jdbc taosdemo
上级
8e75b9e0
1a4746d4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
6 deletion
+62
-6
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
.../java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
+38
-6
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
...a/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
+24
-0
未找到文件。
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/JdbcTaosdemo.java
浏览文件 @
babe8f15
...
@@ -25,7 +25,6 @@ public class JdbcTaosdemo {
...
@@ -25,7 +25,6 @@ public class JdbcTaosdemo {
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
boolean
isHelp
=
Arrays
.
asList
(
args
).
contains
(
"--help"
);
boolean
isHelp
=
Arrays
.
asList
(
args
).
contains
(
"--help"
);
...
@@ -52,7 +51,15 @@ public class JdbcTaosdemo {
...
@@ -52,7 +51,15 @@ public class JdbcTaosdemo {
taosdemo
.
insertInfinite
();
taosdemo
.
insertInfinite
();
}
else
{
}
else
{
taosdemo
.
insertMultiThreads
();
taosdemo
.
insertMultiThreads
();
taosdemo
.
countFromSuperTable
();
// single table select
taosdemo
.
selectFromTableLimit
();
taosdemo
.
selectCountFromTable
();
taosdemo
.
selectAvgMinMaxFromTable
();
// super table select
taosdemo
.
selectFromSuperTableLimit
();
taosdemo
.
selectCountFromSuperTable
();
taosdemo
.
selectAvgMinMaxFromSuperTable
();
// drop super table
if
(
config
.
isDeleteTable
())
if
(
config
.
isDeleteTable
())
taosdemo
.
dropSuperTable
();
taosdemo
.
dropSuperTable
();
taosdemo
.
close
();
taosdemo
.
close
();
...
@@ -174,8 +181,33 @@ public class JdbcTaosdemo {
...
@@ -174,8 +181,33 @@ public class JdbcTaosdemo {
}
}
}
}
private
void
countFromSuperTable
()
{
private
void
selectFromTableLimit
()
{
String
sql
=
"select count(*) from "
+
config
.
getDbName
()
+
"."
+
config
.
getStbName
();
String
sql
=
SqlSpeller
.
selectFromTableLimitSQL
(
config
.
getDbName
(),
config
.
getTbPrefix
(),
1
,
10
,
0
);
executeQuery
(
sql
);
}
private
void
selectCountFromTable
()
{
String
sql
=
SqlSpeller
.
selectCountFromTableSQL
(
config
.
getDbName
(),
config
.
getTbPrefix
(),
1
);
executeQuery
(
sql
);
}
private
void
selectAvgMinMaxFromTable
()
{
String
sql
=
SqlSpeller
.
selectAvgMinMaxFromTableSQL
(
"current"
,
config
.
getDbName
(),
config
.
getTbPrefix
(),
1
);
executeQuery
(
sql
);
}
private
void
selectFromSuperTableLimit
()
{
String
sql
=
SqlSpeller
.
selectFromSuperTableLimitSQL
(
config
.
getDbName
(),
config
.
getStbName
(),
10
,
0
);
executeQuery
(
sql
);
}
private
void
selectCountFromSuperTable
()
{
String
sql
=
SqlSpeller
.
selectCountFromSuperTableSQL
(
config
.
getDbName
(),
config
.
getStbName
());
executeQuery
(
sql
);
}
private
void
selectAvgMinMaxFromSuperTable
()
{
String
sql
=
SqlSpeller
.
selectAvgMinMaxFromSuperTableSQL
(
"current"
,
config
.
getDbName
(),
config
.
getStbName
());
executeQuery
(
sql
);
executeQuery
(
sql
);
}
}
...
@@ -215,7 +247,7 @@ public class JdbcTaosdemo {
...
@@ -215,7 +247,7 @@ public class JdbcTaosdemo {
}
}
private
static
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
private
static
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
logger
.
info
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
}
}
private
void
executeQuery
(
String
sql
)
{
private
void
executeQuery
(
String
sql
)
{
...
@@ -240,7 +272,7 @@ public class JdbcTaosdemo {
...
@@ -240,7 +272,7 @@ public class JdbcTaosdemo {
String
value
=
resultSet
.
getString
(
i
);
String
value
=
resultSet
.
getString
(
i
);
sb
.
append
(
columnLabel
+
": "
+
value
+
"\t"
);
sb
.
append
(
columnLabel
+
": "
+
value
+
"\t"
);
}
}
logger
.
info
(
sb
.
toString
());
System
.
out
.
println
(
sb
.
toString
());
}
}
}
}
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/jdbcTaosdemo/utils/SqlSpeller.java
浏览文件 @
babe8f15
...
@@ -54,5 +54,29 @@ public class SqlSpeller {
...
@@ -54,5 +54,29 @@ public class SqlSpeller {
return
sb
.
toString
();
return
sb
.
toString
();
}
}
public
static
String
selectFromTableLimitSQL
(
String
dbName
,
String
tbPrefix
,
int
tbIndex
,
int
limit
,
int
offset
)
{
return
"select * from "
+
dbName
+
"."
+
tbPrefix
+
""
+
tbIndex
+
" limit "
+
limit
+
" offset "
+
offset
;
}
public
static
String
selectCountFromTableSQL
(
String
dbName
,
String
tbPrefix
,
int
tbIndex
)
{
return
"select count(*) from "
+
dbName
+
"."
+
tbPrefix
+
""
+
tbIndex
;
}
public
static
String
selectAvgMinMaxFromTableSQL
(
String
field
,
String
dbName
,
String
tbPrefix
,
int
tbIndex
)
{
return
"select avg("
+
field
+
"),min("
+
field
+
"),max("
+
field
+
") from "
+
dbName
+
"."
+
tbPrefix
+
""
+
tbIndex
;
}
public
static
String
selectFromSuperTableLimitSQL
(
String
dbName
,
String
stbName
,
int
limit
,
int
offset
)
{
return
"select * from "
+
dbName
+
"."
+
stbName
+
" limit "
+
limit
+
" offset "
+
offset
;
}
public
static
String
selectCountFromSuperTableSQL
(
String
dbName
,
String
stableName
)
{
return
"select count(*) from "
+
dbName
+
"."
+
stableName
;
}
public
static
String
selectAvgMinMaxFromSuperTableSQL
(
String
field
,
String
dbName
,
String
stbName
)
{
return
"select avg("
+
field
+
"),min("
+
field
+
"),max("
+
field
+
") from "
+
dbName
+
"."
+
stbName
+
""
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录