Skip to content

Commit 1b42dba

Browse files
authored
Update 03-jdbc.md (#2258)
Add batch update stmt docs
1 parent ba9868f commit 1b42dba

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

docs/en/developer/00-drivers/03-jdbc.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ To download the Databend JDBC driver:
1717
To verify the version of Databend JDBC driver, for example, _databend-jdbc-0.1.1.jar_, run the following command in the terminal:
1818

1919
```bash
20-
java -jar databend-jdbc-0.2.1.jar --version
20+
java -jar databend-jdbc-0.3.7.jar --version
2121
```
2222

2323
The Databend JDBC driver is provided as a JAR file and can be integrated directly into your Java-based projects. Alternatively, you can declare a Maven dependency in your project's pom.xml file, like so:
@@ -26,7 +26,7 @@ The Databend JDBC driver is provided as a JAR file and can be integrated directl
2626
<dependency>
2727
<groupId>com.databend</groupId>
2828
<artifactId>databend-jdbc</artifactId>
29-
<version>0.2.1</version>
29+
<version>0.3.7</version>
3030
</dependency>
3131
```
3232

@@ -183,6 +183,35 @@ int[] count = pstmt.executeBatch(); // After execution, count[0]=1, count[1]=1
183183
pstmt.close();
184184
```
185185

186+
### Example: Batch Update
187+
You can update multiple rows in a single batch binding parameters in an REPLACE INTO statement and calling addBatch() and executeBatch().
188+
189+
As an example, the following code update the rows which have conflict values in field `a`. The example binds values to the parameters in the REPLACE INTO statement and calls addBatch() and executeBatch() to perform a batch update according to the key field.
190+
```java
191+
Connection c = Utils.createConnection();
192+
c.setAutoCommit(false);
193+
PreparedStatement ps1 = c.prepareStatement("insert into test_prepare_statement values");
194+
ps1.setInt(1, 1);
195+
ps1.setInt(2, 2);
196+
ps1.addBatch();
197+
ps1.executeBatch();
198+
199+
PreparedStatement ps = c.prepareStatement("replace into test_prepare_statement on(a) values");
200+
ps.setInt(1, 1);
201+
ps.setString(2, "a");
202+
ps.addBatch();
203+
ps.setInt(1, 3);
204+
ps.setString(2, "b");
205+
ps.addBatch();
206+
System.out.println("execute batch replace into");
207+
int[] ans = ps.executeBatch();
208+
...
209+
```
210+
211+
:::tip
212+
Databend does not support `executeBatch()` in UPDATE statement. If you want to do batch update, please use REPLACE INTO.
213+
:::
214+
186215
### Example: Uploading Files to an Internal Stage
187216

188217
```java

0 commit comments

Comments
 (0)