[fix](jdbc catalog) Clean up the connection pool after failure to initialize the client (#31949)

This commit is contained in:
zy-kkk
2024-03-09 20:01:56 +08:00
committed by yiguolei
parent 27eed5399d
commit 1fee736ca4
3 changed files with 9 additions and 7 deletions

View File

@ -169,8 +169,8 @@ public abstract class JdbcClient {
try {
conn = dataSource.getConnection();
} catch (Exception e) {
String errorMessage = String.format("Can not connect to jdbc due to error: %s, Catalog name: %s", e,
this.getCatalogName());
String errorMessage = String.format("Can not connect to jdbc due to error: %s, Catalog name: %s",
e.getMessage(), this.getCatalogName());
throw new JdbcClientException(errorMessage, e);
}
return conn;

View File

@ -54,8 +54,9 @@ public class JdbcMySQLClient extends JdbcClient {
String versionComment = rs.getString("Value");
isDoris = versionComment.toLowerCase().contains("doris");
}
} catch (SQLException e) {
throw new JdbcClientException("Failed to determine MySQL Version Comment", e);
} catch (SQLException | JdbcClientException e) {
closeClient();
throw new JdbcClientException("Failed to initialize JdbcMySQLClient: %s", e.getMessage());
} finally {
close(rs, stmt, conn);
}

View File

@ -47,11 +47,12 @@ public class JdbcOceanBaseClient extends JdbcClient {
currentClient = new JdbcOracleClient(jdbcClientConfig);
setOracleMode();
} else {
throw new JdbcClientException("Unsupported compatibility mode: " + compatibilityMode);
throw new JdbcClientException("Unsupported OceanBase compatibility mode: " + compatibilityMode);
}
}
} catch (SQLException e) {
throw new JdbcClientException("Failed to determine OceanBase compatibility mode", e);
} catch (SQLException | JdbcClientException e) {
closeClient();
throw new JdbcClientException("Failed to initialize JdbcOceanBaseClient", e.getMessage());
} finally {
close(rs, stmt, conn);
}