Skip to content

Commit afc2ca7

Browse files
authored
add batch example fo JDBC. (#2785)
1 parent af6fd9d commit afc2ca7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,19 @@ PreparedStatement pstmt = conn.prepareStatement("INSERT INTO users VALUES (?, ?,
8282
pstmt.setInt(1, 1);
8383
pstmt.setString(2, "Alice");
8484
pstmt.setString(3, "[email protected]");
85-
pstmt.executeUpdate();
85+
int result = pstmt.executeUpdate();
86+
87+
// Write: Insert data with executeBatch
88+
pstmt = conn.prepareStatement("INSERT INTO users VALUES (?, ?, ?)");
89+
pstmt.setInt(1, 2);
90+
pstmt.setString(2, "Bob");
91+
pstmt.setString(3, "[email protected]");
92+
pstmt.addBatch();
93+
pstmt.setInt(1, 3);
94+
pstmt.setString(2, "John");
95+
pstmt.setString(3, "[email protected]");
96+
pstmt.addBatch();
97+
int[] results = pstmt.executeBatch();
8698

8799
// Query: Select data
88100
ResultSet rs = stmt.executeQuery("SELECT id, name, email FROM users WHERE id = 1");
@@ -114,5 +126,3 @@ Please refer to the [official databend-jdbc Connection Guide](https://github.com
114126
- **Maven Central**: [databend-jdbc](https://repo1.maven.org/maven2/com/databend/databend-jdbc/)
115127
- **GitHub Repository**: [databend-jdbc](https://github.com/databendlabs/databend-jdbc)
116128
- **JDBC Documentation**: [Oracle JDBC Guide](https://docs.oracle.com/javase/tutorial/jdbc/)
117-
118-

0 commit comments

Comments
 (0)