Skip to content

Commit 9ffda1d

Browse files
committed
feedback
1 parent 2a7543b commit 9ffda1d

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,15 +2638,27 @@ Schema defineGetVersionColumnsSchema() {
26382638
return Schema.of(fields);
26392639
}
26402640

2641+
private void closeStatementIgnoreException(Statement statement){
2642+
if (statement == null){
2643+
return;
2644+
}
2645+
try {
2646+
statement.close();
2647+
} catch (SQLException e){
2648+
// pass
2649+
}
2650+
}
2651+
26412652
@Override
26422653
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
26432654
String sql = readSqlFromFile(GET_PRIMARY_KEYS_SQL);
2655+
Statement stmt = this.connection.createStatement();
26442656
try {
2645-
Statement stmt = this.connection.createStatement();
26462657
stmt.closeOnCompletion();
26472658
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
26482659
return stmt.executeQuery(formattedSql);
26492660
} catch (SQLException e) {
2661+
closeStatementIgnoreException(stmt);
26502662
throw new BigQueryJdbcException("Error executing getPrimaryKeys", e);
26512663
}
26522664
}
@@ -2655,12 +2667,13 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
26552667
public ResultSet getImportedKeys(String catalog, String schema, String table)
26562668
throws SQLException {
26572669
String sql = readSqlFromFile(GET_IMPORTED_KEYS_SQL);
2670+
Statement stmt = this.connection.createStatement();
26582671
try {
2659-
Statement stmt = this.connection.createStatement();
26602672
stmt.closeOnCompletion();
26612673
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
26622674
return stmt.executeQuery(formattedSql);
26632675
} catch (SQLException e) {
2676+
closeStatementIgnoreException(stmt);
26642677
throw new BigQueryJdbcException("Error executing getImportedKeys", e);
26652678
}
26662679
}
@@ -2669,12 +2682,13 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
26692682
public ResultSet getExportedKeys(String catalog, String schema, String table)
26702683
throws SQLException {
26712684
String sql = readSqlFromFile(GET_EXPORTED_KEYS_SQL);
2685+
Statement stmt = this.connection.createStatement();
26722686
try {
2673-
Statement stmt = this.connection.createStatement();
26742687
stmt.closeOnCompletion();
26752688
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
26762689
return stmt.executeQuery(formattedSql);
26772690
} catch (SQLException e) {
2691+
closeStatementIgnoreException(stmt);
26782692
throw new BigQueryJdbcException("Error executing getExportedKeys", e);
26792693
}
26802694
}
@@ -2689,8 +2703,8 @@ public ResultSet getCrossReference(
26892703
String foreignTable)
26902704
throws SQLException {
26912705
String sql = readSqlFromFile(GET_CROSS_REFERENCE_SQL);
2706+
Statement stmt = this.connection.createStatement();
26922707
try {
2693-
Statement stmt = this.connection.createStatement();
26942708
stmt.closeOnCompletion();
26952709
String formattedSql =
26962710
replaceSqlParameters(
@@ -2703,6 +2717,7 @@ public ResultSet getCrossReference(
27032717
foreignTable);
27042718
return stmt.executeQuery(formattedSql);
27052719
} catch (SQLException e) {
2720+
closeStatementIgnoreException(stmt);
27062721
throw new BigQueryJdbcException("Error executing getCrossReference", e);
27072722
}
27082723
}

0 commit comments

Comments
 (0)