Merge pull request #29537 from taosdata/docs/improve-stmt-doc
add note for sql using in parameter binding insertion
This commit is contained in:
commit
cfb2919291
|
@ -15,6 +15,19 @@ When inserting data using parameter binding, it can avoid the resource consumpti
|
|||
|
||||
**Tips: It is recommended to use parameter binding for data insertion**
|
||||
|
||||
:::note
|
||||
We only recommend using the following two forms of SQL for parameter binding data insertion:
|
||||
|
||||
```sql
|
||||
a. Subtables already exists:
|
||||
1. INSERT INTO meters (tbname, ts, current, voltage, phase) VALUES(?, ?, ?, ?, ?)
|
||||
b. Automatic table creation on insert:
|
||||
1. INSERT INTO meters (tbname, ts, current, voltage, phase, location, group_id) VALUES(?, ?, ?, ?, ?, ?, ?)
|
||||
2. INSERT INTO ? USING meters TAGS (?, ?) VALUES (?, ?, ?, ?)
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
Next, we continue to use smart meters as an example to demonstrate the efficient writing functionality of parameter binding with various language connectors:
|
||||
|
||||
1. Prepare a parameterized SQL insert statement for inserting data into the supertable `meters`. This statement allows dynamically specifying subtable names, tags, and column values.
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
package com.taosdata.example;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.taosdata.jdbc.AbstractStatement;
|
||||
|
||||
import java.sql.*;
|
||||
|
|
|
@ -104,8 +104,9 @@ public class JdbcDemo {
|
|||
|
||||
private void executeQuery(String sql) {
|
||||
long start = System.currentTimeMillis();
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
try (Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(sql)) {
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
printSql(sql, true, (end - start));
|
||||
Util.printResult(resultSet);
|
||||
|
|
|
@ -15,6 +15,19 @@ import TabItem from "@theme/TabItem";
|
|||
|
||||
**Tips: 数据写入推荐使用参数绑定方式**
|
||||
|
||||
:::note
|
||||
我们只推荐使用下面两种形式的 SQL 进行参数绑定写入:
|
||||
|
||||
```sql
|
||||
一、确定子表存在:
|
||||
1. INSERT INTO meters (tbname, ts, current, voltage, phase) VALUES(?, ?, ?, ?, ?)
|
||||
二、自动建表:
|
||||
1. INSERT INTO meters (tbname, ts, current, voltage, phase, location, group_id) VALUES(?, ?, ?, ?, ?, ?, ?)
|
||||
2. INSERT INTO ? USING meters TAGS (?, ?) VALUES (?, ?, ?, ?)
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
下面我们继续以智能电表为例,展示各语言连接器使用参数绑定高效写入的功能:
|
||||
1. 准备一个参数化的 SQL 插入语句,用于向超级表 `meters` 中插入数据。这个语句允许动态地指定子表名、标签和列值。
|
||||
2. 循环生成多个子表及其对应的数据行。对于每个子表:
|
||||
|
|
Loading…
Reference in New Issue