Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
971d98f5
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
971d98f5
编写于
3月 26, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
cfd66a8f
634bf6bc
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
83 addition
and
29 deletion
+83
-29
docs-cn/06-insert-data/01-sql-writing.mdx
docs-cn/06-insert-data/01-sql-writing.mdx
+1
-2
docs-cn/06-insert-data/_java_stmt.mdx
docs-cn/06-insert-data/_java_stmt.mdx
+1
-1
docs-cn/07-query-data/_java.mdx
docs-cn/07-query-data/_java.mdx
+3
-0
docs-cn/07-query-data/index.mdx
docs-cn/07-query-data/index.mdx
+7
-8
docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java
...java/src/main/java/com/taos/example/RestQueryExample.java
+55
-0
docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java
...ava/src/main/java/com/taos/example/StmtInsertExample.java
+16
-18
未找到文件。
docs-cn/06-insert-data/01-sql-writing.mdx
浏览文件 @
971d98f5
...
...
@@ -117,7 +117,6 @@ TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 一样,这
</Tabs>
:::note
只有使用本地驱动方式建立连接,才能使用动态绑定工具。
只有使用本地驱动方式连接连接,才能使用动态绑定功能。
:::
docs-cn/06-insert-data/_java_stmt.mdx
浏览文件 @
971d98f5
```java
{{#include docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java
:insert
}}
{{#include docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java}}
```
docs-cn/07-query-data/_java.mdx
浏览文件 @
971d98f5
```java
{{#include docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java}}
```
docs-cn/07-query-data/index.mdx
浏览文件 @
971d98f5
...
...
@@ -123,25 +123,25 @@ Query OK, 5 row(s) in set (0.001521s)
<Tabs defaultValue="java" groupId="lang">
<TabItem label="Java" value="java">
<Java
Stmt
/>
<Java
Query
/>
</TabItem>
<TabItem label="Python" value="python">
<Py
Stmt
/>
<Py
Query
/>
</TabItem>
<TabItem label="Go" value="go">
<Go
Stmt
/>
<Go
Query
/>
</TabItem>
<TabItem label="Rust" value="rust">
<Rust
Stmt
/>
<Rust
Query
/>
</TabItem>
<TabItem label="Node.js" value="nodejs">
<Node
Stmt
/>
<Node
Query
/>
</TabItem>
<TabItem label="C#" value="csharp">
<Cs
Stmt
/>
<Cs
Query
/>
</TabItem>
<TabItem label="C" value="c">
<C
Stmt
/>
<C
Query
/>
</TabItem>
</Tabs>
...
...
@@ -177,4 +177,3 @@ Query OK, 5 row(s) in set (0.001521s)
只有使用本地驱动方式连接连接,才能使用异步查询功能。
:::
docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java
0 → 100644
浏览文件 @
971d98f5
package
com.taos.example
;
import
java.sql.*
;
public
class
RestQueryExample
{
private
static
Connection
getConnection
()
throws
SQLException
{
String
jdbcUrl
=
"jdbc:TAOS-RS://localhost:6041/power?user=root&password=taosdata"
;
return
DriverManager
.
getConnection
(
jdbcUrl
);
}
private
static
void
printRow
(
ResultSet
rs
)
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
String
value
=
rs
.
getString
(
i
);
System
.
out
.
print
(
value
);
System
.
out
.
print
(
"\t"
);
}
System
.
out
.
println
();
}
private
static
void
printColName
(
ResultSet
rs
)
throws
SQLException
{
ResultSetMetaData
meta
=
rs
.
getMetaData
();
for
(
int
i
=
1
;
i
<=
meta
.
getColumnCount
();
i
++)
{
String
colLabel
=
meta
.
getColumnLabel
(
i
);
System
.
out
.
print
(
colLabel
);
System
.
out
.
print
(
"\t"
);
}
System
.
out
.
println
();
}
private
static
void
processResult
(
ResultSet
rs
)
throws
SQLException
{
printColName
(
rs
);
while
(
rs
.
next
())
{
printRow
(
rs
);
}
}
private
static
void
queryData
()
throws
SQLException
{
try
(
Connection
conn
=
getConnection
())
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT AVG(voltage) FROM meters GROUP BY location"
);
processResult
(
rs
);
}
}
}
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
queryData
();
}
}
// possible stdout:
// avg(voltage) location
// 222.0 Beijing.Haidian
// 219.0 Beijing.Chaoyang
docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java
浏览文件 @
971d98f5
...
...
@@ -14,9 +14,18 @@ import java.util.Arrays;
import
java.util.List
;
public
class
StmtInsertExample
{
private
static
Connection
getConnection
()
throws
SQLException
{
String
jdbcUrl
=
"jdbc:TAOS://localhost:6030?user=root&password=taosdata"
;
return
DriverManager
.
getConnection
(
jdbcUrl
);
private
static
ArrayList
<
Long
>
tsToLongArray
(
String
ts
)
{
ArrayList
<
Long
>
result
=
new
ArrayList
<>();
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss.SSS"
);
LocalDateTime
localDateTime
=
LocalDateTime
.
parse
(
ts
,
formatter
);
result
.
add
(
localDateTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
());
return
result
;
}
private
static
<
T
>
ArrayList
<
T
>
toArray
(
T
v
)
{
ArrayList
<
T
>
result
=
new
ArrayList
<>();
result
.
add
(
v
);
return
result
;
}
private
static
List
<
String
>
getRawData
()
{
...
...
@@ -32,21 +41,11 @@ public class StmtInsertExample {
);
}
private
static
ArrayList
<
Long
>
tsToLongArray
(
String
ts
)
{
ArrayList
<
Long
>
result
=
new
ArrayList
<>();
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss.SSS"
);
LocalDateTime
localDateTime
=
LocalDateTime
.
parse
(
ts
,
formatter
);
result
.
add
(
localDateTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
());
return
result
;
}
private
static
<
T
>
ArrayList
<
T
>
toArray
(
T
v
)
{
ArrayList
<
T
>
result
=
new
ArrayList
<>();
result
.
add
(
v
);
return
result
;
private
static
Connection
getConnection
()
throws
SQLException
{
String
jdbcUrl
=
"jdbc:TAOS://localhost:6030?user=root&password=taosdata"
;
return
DriverManager
.
getConnection
(
jdbcUrl
);
}
// ANCHOR: insert
private
static
void
createTable
(
Connection
conn
)
throws
SQLException
{
try
(
Statement
stmt
=
conn
.
createStatement
())
{
stmt
.
execute
(
"CREATE DATABASE power KEEP 3650"
);
...
...
@@ -68,7 +67,7 @@ public class StmtInsertExample {
pst
.
setTagString
(
0
,
ps
[
5
]);
pst
.
setTagInt
(
1
,
Integer
.
valueOf
(
ps
[
6
]));
// bind values
pst
.
setTimestamp
(
0
,
tsToLongArray
(
ps
[
1
]));
pst
.
setTimestamp
(
0
,
tsToLongArray
(
ps
[
1
]));
//ps[1] looks like: 2018-10-03 14:38:05.000
pst
.
setFloat
(
1
,
toArray
(
Float
.
valueOf
(
ps
[
2
])));
pst
.
setInt
(
2
,
toArray
(
Integer
.
valueOf
(
ps
[
3
])));
pst
.
setFloat
(
3
,
toArray
(
Float
.
valueOf
(
ps
[
4
])));
...
...
@@ -78,7 +77,6 @@ public class StmtInsertExample {
}
}
}
// ANCHOR_END: insert
public
static
void
main
(
String
[]
args
)
throws
SQLException
{
insertData
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录