Skip to content

Commit 52819c2

Browse files
fix: Update 03-jdbc.md (#1101)
* Update 03-jdbc.md fix demo code * Update 03-jdbc.md * Update 03-jdbc.md * Update 03-jdbc.md --------- Co-authored-by: Quan <[email protected]>
1 parent 16bab97 commit 52819c2

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ package com.example;
101101
import java.sql.*;
102102
import java.util.Properties;
103103

104-
public class demo {
104+
public class Main {
105105
// Connecting to a local Databend with a SQL user named 'user1' and password 'abc123' as an example.
106106
// Feel free to use your own values while maintaining the same format.
107107
static final String DB_URL = "jdbc:databend://127.0.0.1:8000";
@@ -126,6 +126,8 @@ public class demo {
126126
stmt.close();
127127
conn.close();
128128
System.exit(0);
129+
}
130+
}
129131
```
130132

131133
### Example: Copy into or merge into table
@@ -263,7 +265,7 @@ Before you start, make sure you have successfully created a warehouse and obtain
263265
<dependency>
264266
<groupId>com.databend</groupId>
265267
<artifactId>databend-jdbc</artifactId>
266-
<version>0.2.1</version>
268+
<version>0.2.8</version>
267269
</dependency>
268270
```
269271

@@ -274,11 +276,7 @@ Create a file named `sample.java` with the following code:
274276
```java
275277
package databend_cloud;
276278

277-
import java.sql.SQLException;
278-
import java.sql.DriverManager;
279-
import java.sql.Connection;
280-
import java.sql.Statement;
281-
import java.sql.ResultSet;
279+
import java.sql.*;
282280
import java.util.Properties;
283281

284282
public class sample {
@@ -314,18 +312,18 @@ public class sample {
314312
ps.setString(5, "[1,2,3,4,5]");
315313
ps.addBatch();
316314
int[] ans = ps.executeBatch();
317-
Statement statement = c.createStatement();
318-
319-
System.out.println("execute select on object");
320-
statement.execute("SELECT * from objects_test1");
321-
ResultSet r = statement.getResultSet();
322-
323-
while (r.next()) {
324-
System.out.println(r.getInt(1));
325-
System.out.println(r.getString(2));
326-
System.out.println(r.getTimestamp(3).toString());
327-
System.out.println(r.getString(4));
328-
System.out.println(r.getString(5));
315+
Statement s = connection.createStatement();
316+
317+
System.out.println("execute select on table");
318+
statement.execute("SELECT * from sample_test");
319+
ResultSet r2 = statement.getResultSet();
320+
321+
while (r2.next()) {
322+
System.out.println(r2.getInt(1));
323+
System.out.println(r2.getString(2));
324+
System.out.println(r2.getTimestamp(3).toString());
325+
System.out.println(r2.getString(4));
326+
System.out.println(r2.getString(5));
329327
}
330328
connection.close();
331329
}

0 commit comments

Comments
 (0)