Skip to content

Commit

Permalink
Consistent code style for Appender sample
Browse files Browse the repository at this point in the history
The statement was close()'d very late.

Apply try-with-resources to release the statement; this is easier on the eyes and improves code flow.
  • Loading branch information
shoffmeister authored Sep 14, 2024
1 parent 4deff1e commit 840bd91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/api/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ import java.sql.Statement;
import org.duckdb.DuckDBConnection;

DuckDBConnection conn = (DuckDBConnection) DriverManager.getConnection("jdbc:duckdb:");
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE tbl (x BIGINT, y FLOAT, s VARCHAR)");
try (var stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE tbl (x BIGINT, y FLOAT, s VARCHAR)"
);

// using try-with-resources to automatically close the appender at the end of the scope
try (var appender = conn.createAppender(DuckDBConnection.DEFAULT_SCHEMA, "tbl")) {
Expand All @@ -220,7 +221,6 @@ try (var appender = conn.createAppender(DuckDBConnection.DEFAULT_SCHEMA, "tbl"))
appender.append("world");
appender.endRow();
}
stmt.close();
```

### Batch Writer
Expand Down

0 comments on commit 840bd91

Please sign in to comment.