Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
70bed137
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
70bed137
编写于
1月 27, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
2839d497
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
41 addition
and
52 deletion
+41
-52
tests/examples/JDBC/JDBCDemo/pom.xml
tests/examples/JDBC/JDBCDemo/pom.xml
+8
-8
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java
...JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java
+30
-40
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java
...o/src/main/java/com/taosdata/example/JdbcRestfulDemo.java
+3
-3
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java
...emo/src/main/java/com/taosdata/example/SubscribeDemo.java
+0
-1
未找到文件。
tests/examples/JDBC/JDBCDemo/pom.xml
浏览文件 @
70bed137
...
...
@@ -9,6 +9,14 @@
<version>
SNAPSHOT
</version>
<packaging>
jar
</packaging>
<dependencies>
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.18
</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
...
...
@@ -48,12 +56,4 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.18
</version>
</dependency>
</dependencies>
</project>
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JDBCDemo.java
浏览文件 @
70bed137
...
...
@@ -5,7 +5,6 @@ import java.util.Properties;
public
class
JDBCDemo
{
private
static
String
host
;
private
static
String
driverType
=
"jni"
;
private
static
final
String
dbName
=
"test"
;
private
static
final
String
tbName
=
"weather"
;
private
Connection
connection
;
...
...
@@ -14,17 +13,10 @@ public class JDBCDemo {
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
if
(
"-host"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
host
=
args
[++
i
];
if
(
"-driverType"
.
equalsIgnoreCase
(
args
[
i
])
&&
i
<
args
.
length
-
1
)
{
driverType
=
args
[++
i
];
if
(!
"jni"
.
equalsIgnoreCase
(
driverType
)
&&
!
"restful"
.
equalsIgnoreCase
(
driverType
))
printHelp
();
}
}
if
(
host
==
null
)
{
printHelp
();
}
JDBCDemo
demo
=
new
JDBCDemo
();
demo
.
init
();
demo
.
createDatabase
();
...
...
@@ -38,15 +30,10 @@ public class JDBCDemo {
}
private
void
init
()
{
final
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
// get connection
try
{
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
if
(
driverType
.
equals
(
"restful"
))
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=root&password=taosdata"
;
}
else
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"locale"
,
"en_US.UTF-8"
);
...
...
@@ -70,11 +57,39 @@ public class JDBCDemo {
exuete
(
sql
);
}
private
void
dropTable
()
{
final
String
sql
=
"drop table if exists "
+
dbName
+
"."
+
tbName
+
""
;
exuete
(
sql
);
}
private
void
createTable
()
{
final
String
sql
=
"create table if not exists "
+
dbName
+
"."
+
tbName
+
" (ts timestamp, temperature float, humidity int)"
;
exuete
(
sql
);
}
private
void
insert
()
{
final
String
sql
=
"insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)"
;
exuete
(
sql
);
}
private
void
select
()
{
final
String
sql
=
"select * from test.weather"
;
executeQuery
(
sql
);
}
private
void
close
()
{
try
{
if
(
connection
!=
null
)
{
this
.
connection
.
close
();
System
.
out
.
println
(
"connection closed."
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
/************************************************************************/
private
void
executeQuery
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
...
...
@@ -99,15 +114,6 @@ public class JDBCDemo {
}
}
private
void
insert
()
{
final
String
sql
=
"insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)"
;
exuete
(
sql
);
}
private
void
createTable
()
{
final
String
sql
=
"create table if not exists "
+
dbName
+
"."
+
tbName
+
" (ts timestamp, temperature float, humidity int)"
;
exuete
(
sql
);
}
private
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
...
...
@@ -125,22 +131,6 @@ public class JDBCDemo {
}
}
private
void
close
()
{
try
{
if
(
connection
!=
null
)
{
this
.
connection
.
close
();
System
.
out
.
println
(
"connection closed."
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
void
dropTable
()
{
final
String
sql
=
"drop table if exists "
+
dbName
+
"."
+
tbName
+
""
;
exuete
(
sql
);
}
private
static
void
printHelp
()
{
System
.
out
.
println
(
"Usage: java -jar JdbcDemo.jar -host <hostname> -driverType <jni|restful>"
);
System
.
exit
(
0
);
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcRestfulDemo.java
浏览文件 @
70bed137
...
...
@@ -14,9 +14,9 @@ public class JdbcRestfulDemo {
String
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=root&password=taosdata"
;
Properties
properties
=
new
Properties
();
//
properties.setProperty("charset", "UTF-8");
//
properties.setProperty("locale", "en_US.UTF-8");
//
properties.setProperty("timezone", "UTC-8");
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"locale"
,
"en_US.UTF-8"
);
properties
.
setProperty
(
"timezone"
,
"UTC-8"
);
Connection
conn
=
DriverManager
.
getConnection
(
url
,
properties
);
Statement
stmt
=
conn
.
createStatement
();
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/SubscribeDemo.java
浏览文件 @
70bed137
...
...
@@ -13,7 +13,6 @@ public class SubscribeDemo {
public
static
TSDBConnection
getConnection
(
String
host
,
String
database
)
throws
Exception
{
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"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录