diff --git a/docs-cn/06-insert-data/01-sql-writing.mdx b/docs-cn/06-insert-data/01-sql-writing.mdx
index 16616487bcd30d48ec965129ca3ec1a8ff9749fd..c49ddc025e7def643b7a25320912d4a42f1d61e2 100644
--- a/docs-cn/06-insert-data/01-sql-writing.mdx
+++ b/docs-cn/06-insert-data/01-sql-writing.mdx
@@ -118,6 +118,6 @@ TDengine 也提供了支持参数绑定的 Prepare API,与 MySQL 一样,这
:::note
-只有使用本地驱动方式连接连接,才能使用动态绑定工具。
+只有使用本地驱动方式连接连接,才能使用动态绑定功能。
:::
diff --git a/docs-cn/06-insert-data/_java_stmt.mdx b/docs-cn/06-insert-data/_java_stmt.mdx
index 9f3e7a4466ba4316b45c2a6fcf3b4e668aa6b0b3..54443e535fa84bdf8dc9161ed4ad00f50b26266c 100644
--- a/docs-cn/06-insert-data/_java_stmt.mdx
+++ b/docs-cn/06-insert-data/_java_stmt.mdx
@@ -1,3 +1,3 @@
```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}}
```
diff --git a/docs-cn/07-query-data/_java.mdx b/docs-cn/07-query-data/_java.mdx
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..519b9266144486231caf3ee593e973d438941ee4 100644
--- a/docs-cn/07-query-data/_java.mdx
+++ b/docs-cn/07-query-data/_java.mdx
@@ -0,0 +1,3 @@
+```java
+{{#include docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java}}
+```
diff --git a/docs-cn/07-query-data/index.mdx b/docs-cn/07-query-data/index.mdx
index 1bea16873d9385d7667cc7b6e2fead7c8c0d1ad6..7f492a971de466dcfc149cc9f88f48096c0228d3 100644
--- a/docs-cn/07-query-data/index.mdx
+++ b/docs-cn/07-query-data/index.mdx
@@ -123,25 +123,25 @@ Query OK, 5 row(s) in set (0.001521s)
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -177,4 +177,3 @@ Query OK, 5 row(s) in set (0.001521s)
只有使用本地驱动方式连接连接,才能使用异步查询功能。
:::
-
diff --git a/docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java b/docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java
new file mode 100644
index 0000000000000000000000000000000000000000..959e003fe81cadaf9c7bdec8d3d337cafdfe6e15
--- /dev/null
+++ b/docs-examples/java/src/main/java/com/taos/example/RestQueryExample.java
@@ -0,0 +1,55 @@
+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
diff --git a/docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java b/docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java
index 2e89e9290a56b133c1ac4b1417ffd7294ccb4a2c..2a7ccebf41cae1a22d7516966e2c6ffb10011b64 100644
--- a/docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java
+++ b/docs-examples/java/src/main/java/com/taos/example/StmtInsertExample.java
@@ -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 tsToLongArray(String ts) {
+ ArrayList 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 ArrayList toArray(T v) {
+ ArrayList result = new ArrayList<>();
+ result.add(v);
+ return result;
}
private static List getRawData() {
@@ -32,21 +41,11 @@ public class StmtInsertExample {
);
}
- private static ArrayList tsToLongArray(String ts) {
- ArrayList 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 ArrayList toArray(T v) {
- ArrayList 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();