Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_40195168达庆意
TDengine
提交
f9aef575
TDengine
项目概览
weixin_40195168达庆意
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
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,体验更适合开发者的 AI 搜索 >>
提交
f9aef575
编写于
5月 27, 2020
作者:
H
Hui Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[sync master]
上级
b9bb2048
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
118 addition
and
1 deletion
+118
-1
tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample.java
.../examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample.java
+1
-1
tests/examples/JDBC/JDBCDemo/src/main/java/TestAsyncTSDBSubscribeSample.java
.../JDBCDemo/src/main/java/TestAsyncTSDBSubscribeSample.java
+58
-0
tests/examples/JDBC/JDBCDemo/src/main/java/TestTSDBSubscribeSample.java
.../JDBC/JDBCDemo/src/main/java/TestTSDBSubscribeSample.java
+59
-0
未找到文件。
tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample.java
浏览文件 @
f9aef575
...
...
@@ -4,7 +4,7 @@ public class TSDBSyncSample {
private
static
final
String
JDBC_PROTOCAL
=
"jdbc:TAOS://"
;
private
static
final
String
TSDB_DRIVER
=
"com.taosdata.jdbc.TSDBDriver"
;
private
String
host
=
"1
27.0.0.1
"
;
private
String
host
=
"1
0.211.55.3
"
;
private
String
user
=
"root"
;
private
String
password
=
"powerdb"
;
//"taosdata";
private
int
port
=
0
;
...
...
tests/examples/JDBC/JDBCDemo/src/main/java/TestAsyncTSDBSubscribeSample.java
0 → 100644
浏览文件 @
f9aef575
import
com.taosdata.jdbc.*
;
import
org.apache.commons.lang3.StringUtils
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.util.Properties
;
public
class
TestAsyncTSDBSubscribeSample
{
public
static
void
main
(
String
[]
args
)
{
String
dbName
=
"log"
;
String
tName
=
"dn_10_211_55_3"
;
String
host
=
"10.211.55.3"
;
String
topic
=
"test"
;
Connection
connection
=
null
;
TSDBSubscribe
subscribe
=
null
;
long
subscribId
=
0
;
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
dbName
+
"?user=root&password=taosdata"
,
properties
);
String
rawSql
=
"select * from "
+
tName
+
";"
;
subscribe
=
((
TSDBConnection
)
connection
).
createSubscribe
();
subscribId
=
subscribe
.
subscribe
(
topic
,
rawSql
,
false
,
1000
,
new
CallBack
(
"first"
));
long
subscribId2
=
subscribe
.
subscribe
(
"test"
,
rawSql
,
false
,
1000
,
new
CallBack
(
"second"
));
int
a
=
0
;
Thread
.
sleep
(
2000
);
subscribe
.
unsubscribe
(
subscribId
,
true
);
System
.
err
.
println
(
"cancel subscribe"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
static
class
CallBack
implements
TSDBSubscribeCallBack
{
private
String
name
=
""
;
public
CallBack
(
String
name
)
{
this
.
name
=
name
;
}
@Override
public
void
invoke
(
TSDBResultSet
resultSet
)
{
try
{
while
(
null
!=
resultSet
&&
resultSet
.
next
())
{
System
.
out
.
print
(
"callback_"
+
name
+
": "
);
for
(
int
i
=
1
;
i
<=
resultSet
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
i
+
": "
+
resultSet
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
}
tests/examples/JDBC/JDBCDemo/src/main/java/TestTSDBSubscribeSample.java
0 → 100644
浏览文件 @
f9aef575
import
com.taosdata.jdbc.TSDBConnection
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.TSDBResultSet
;
import
com.taosdata.jdbc.TSDBSubscribe
;
import
org.apache.commons.lang3.StringUtils
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.util.Properties
;
public
class
TestTSDBSubscribeSample
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// use log db
String
dbName
=
"log"
;
String
tName
=
"dn_10_211_55_3"
;
String
host
=
"10.211.55.3"
;
String
topic
=
"test"
;
Connection
connection
=
null
;
TSDBSubscribe
subscribe
=
null
;
long
subscribId
=
0
;
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
dbName
+
"?user=root&password=taosdata"
,
properties
);
String
rawSql
=
"select * from "
+
tName
+
";"
;
subscribe
=
((
TSDBConnection
)
connection
).
createSubscribe
();
subscribId
=
subscribe
.
subscribe
(
topic
,
rawSql
,
false
,
1000
);
int
a
=
0
;
while
(
true
)
{
Thread
.
sleep
(
1000
);
TSDBResultSet
resSet
=
subscribe
.
consume
(
subscribId
);
while
(
resSet
.
next
())
{
for
(
int
i
=
1
;
i
<=
resSet
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
i
+
": "
+
resSet
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
(
"\n================"
);
}
a
++;
if
(
a
>=
10
)
{
break
;
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
null
!=
subscribe
&&
0
!=
subscribId
)
{
subscribe
.
unsubscribe
(
subscribId
,
true
);
}
if
(
null
!=
connection
)
{
connection
.
close
();
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录