Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
adminstrot
TDengine
提交
21584e30
TDengine
项目概览
adminstrot
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
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,发现更多精彩内容 >>
未验证
提交
21584e30
编写于
9月 13, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
9月 13, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3501 from taosdata/test/TD-1410
[TD-1410]test: add a tool for test JDBC Connector
上级
3ea060e1
e7af1188
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
188 addition
and
16 deletion
+188
-16
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
...r/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
+0
-2
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+14
-14
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java
.../main/java/com/taosdata/example/JDBCConnectorChecker.java
+174
-0
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java
浏览文件 @
21584e30
...
...
@@ -10,8 +10,6 @@ import java.sql.SQLException;
import
java.sql.Statement
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
SubscribeTest
extends
BaseTest
{
Connection
connection
=
null
;
Statement
statement
=
null
;
...
...
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
21584e30
...
...
@@ -9,21 +9,20 @@
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugins
</artifactId>
<version>
30
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
<version>
3.0.0
</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-plugins
</artifactId>
<version>
30
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
<version>
3.0.0
</version>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
...
...
@@ -48,6 +47,7 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCConnectorChecker.java
0 → 100644
浏览文件 @
21584e30
package
com.taosdata.example
;
import
com.taosdata.jdbc.TSDBDriver
;
import
java.sql.*
;
import
java.util.Properties
;
public
class
JDBCConnectorChecker
{
private
static
String
host
;
private
static
String
dbName
=
"test"
;
private
static
String
tbName
=
"weather"
;
private
Connection
connection
;
/**
* get connection
**/
private
void
init
()
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
System
.
out
.
println
(
"get connection starting..."
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
,
properties
);
if
(
connection
!=
null
)
System
.
out
.
println
(
"[ OK ] Connection established."
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
throw
new
RuntimeException
(
"connection failed: "
+
host
);
}
}
/**
* create database
*/
private
void
createDatabase
()
{
String
sql
=
"create database if not exists "
+
dbName
;
exuete
(
sql
);
}
/**
* use database
*/
private
void
useDatabase
()
{
String
sql
=
"use "
+
dbName
;
exuete
(
sql
);
}
/**
* select
*/
private
void
checkSelect
()
{
final
String
sql
=
"select * from test.weather"
;
executeQuery
(
sql
);
}
private
void
executeQuery
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
ResultSet
resultSet
=
statement
.
executeQuery
(
sql
);
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
true
,
(
end
-
start
));
printResult
(
resultSet
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
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
();
}
}
private
String
formatString
(
String
str
)
{
StringBuilder
sb
=
new
StringBuilder
();
int
blankCnt
=
(
26
-
str
.
length
())
/
2
;
for
(
int
j
=
0
;
j
<
blankCnt
;
j
++)
sb
.
append
(
" "
);
sb
.
append
(
str
);
for
(
int
j
=
0
;
j
<
blankCnt
;
j
++)
sb
.
append
(
" "
);
sb
.
append
(
"|"
);
return
sb
.
toString
();
}
/**
* insert
*/
private
void
checkInsert
()
{
final
String
sql
=
"insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)"
;
exuete
(
sql
);
}
/**
* create table
*/
private
void
createTable
()
{
final
String
sql
=
"create table if not exists "
+
dbName
+
"."
+
tbName
+
" (ts timestamp, temperature float, humidity int)"
;
exuete
(
sql
);
}
private
final
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
}
private
final
void
exuete
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
boolean
execute
=
statement
.
execute
(
sql
);
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
execute
,
(
end
-
start
));
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
void
close
()
{
try
{
if
(
connection
!=
null
)
{
this
.
connection
.
close
();
System
.
out
.
println
(
"connection closed."
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
void
checkDropTable
()
{
final
String
sql
=
"drop table if exists "
+
dbName
+
"."
+
tbName
+
""
;
exuete
(
sql
);
}
public
static
void
main
(
String
[]
args
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
"-host"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
host
=
args
[++
i
];
}
if
(
"-db"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
dbName
=
args
[++
i
];
}
if
(
"-t"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
tbName
=
args
[++
i
];
}
}
if
(
host
==
null
)
{
System
.
out
.
println
(
"Usage: java -jar JDBCConnectorChecker.jar -host <hostname>"
);
return
;
}
JDBCConnectorChecker
checker
=
new
JDBCConnectorChecker
();
checker
.
init
();
checker
.
createDatabase
();
checker
.
useDatabase
();
checker
.
checkDropTable
();
checker
.
createTable
();
checker
.
checkInsert
();
checker
.
checkSelect
();
checker
.
checkDropTable
();
checker
.
close
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录