Skip to content

Commit 729618f

Browse files
committed
use try-with-resources to improve the code
1 parent facd97d commit 729618f

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

java/connector-node/risingwave-sink-jdbc/src/main/java/com/risingwave/connector/JDBCSinkFactory.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,17 @@ public void validate(
5757
Set<String> jdbcColumns = new HashSet<>();
5858
Set<String> jdbcPk = new HashSet<>();
5959

60-
try {
61-
Connection conn = DriverManager.getConnection(jdbcUrl);
62-
63-
ResultSet columnResultSet = conn.getMetaData().getColumns(null, null, tableName, null);
60+
try (Connection conn = DriverManager.getConnection(jdbcUrl);
61+
ResultSet columnResultSet =
62+
conn.getMetaData().getColumns(null, null, tableName, null);
63+
ResultSet pkResultSet =
64+
conn.getMetaData().getPrimaryKeys(null, null, tableName); ) {
6465
while (columnResultSet.next()) {
6566
jdbcColumns.add(columnResultSet.getString("COLUMN_NAME"));
6667
}
67-
68-
ResultSet pkResultSet = conn.getMetaData().getPrimaryKeys(null, null, tableName);
6968
while (pkResultSet.next()) {
7069
jdbcPk.add(pkResultSet.getString("COLUMN_NAME"));
7170
}
72-
73-
conn.close();
7471
} catch (SQLException e) {
7572
throw Status.INTERNAL.withCause(e).asRuntimeException();
7673
}

0 commit comments

Comments
 (0)