@@ -101,7 +101,7 @@ package com.example;
101
101
import java.sql.* ;
102
102
import java.util.Properties ;
103
103
104
- public class demo {
104
+ public class Main {
105
105
// Connecting to a local Databend with a SQL user named 'user1' and password 'abc123' as an example.
106
106
// Feel free to use your own values while maintaining the same format.
107
107
static final String DB_URL = " jdbc:databend://127.0.0.1:8000" ;
@@ -126,6 +126,8 @@ public class demo {
126
126
stmt. close();
127
127
conn. close();
128
128
System . exit(0 );
129
+ }
130
+ }
129
131
```
130
132
131
133
### Example: Copy into or merge into table
@@ -263,7 +265,7 @@ Before you start, make sure you have successfully created a warehouse and obtain
263
265
<dependency >
264
266
<groupId >com.databend</groupId >
265
267
<artifactId >databend-jdbc</artifactId >
266
- <version>0.2.1 </version>
268
+ <version >0.2.8 </version >
267
269
</dependency >
268
270
```
269
271
@@ -274,11 +276,7 @@ Create a file named `sample.java` with the following code:
274
276
``` java
275
277
package databend_cloud ;
276
278
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.* ;
282
280
import java.util.Properties ;
283
281
284
282
public class sample {
@@ -314,18 +312,18 @@ public class sample {
314
312
ps. setString(5 , " [1,2,3,4,5]" );
315
313
ps. addBatch();
316
314
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 ));
329
327
}
330
328
connection. close();
331
329
}
0 commit comments