未验证 提交 8da64d79 编写于 作者: K kougazhang 提交者: GitHub

[FLINK-20540][jdbc] Fix JdbcCatalog connection exception when baseUrl doesn't end with slash

This closes #14362
Co-authored-by: Nzhao.zhang <zhao.zhang@upai.com>
上级 2848d4d4
......@@ -88,7 +88,7 @@ public abstract class AbstractJdbcCatalog extends AbstractCatalog {
this.username = username;
this.pwd = pwd;
this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
this.defaultUrl = baseUrl + defaultDatabase;
this.defaultUrl = this.baseUrl + defaultDatabase;
}
@Override
......
......@@ -68,7 +68,7 @@ public class PostgresCatalogTestBase {
// jdbc:postgresql://localhost:50807/postgres?user=postgres
String embeddedJdbcUrl = pg.getEmbeddedPostgres().getJdbcUrl(TEST_USERNAME, TEST_PWD);
// jdbc:postgresql://localhost:50807/
baseUrl = embeddedJdbcUrl.substring(0, embeddedJdbcUrl.lastIndexOf("/") + 1);
baseUrl = embeddedJdbcUrl.substring(0, embeddedJdbcUrl.lastIndexOf("/"));
catalog = new PostgresCatalog(TEST_CATALOG_NAME, PostgresCatalog.DEFAULT_DATABASE, TEST_USERNAME, TEST_PWD, baseUrl);
......@@ -122,7 +122,7 @@ public class PostgresCatalogTestBase {
}
public static void executeSQL(String db, String sql) throws SQLException {
try (Connection conn = DriverManager.getConnection(baseUrl + db, TEST_USERNAME, TEST_PWD);
try (Connection conn = DriverManager.getConnection(String.format("%s/%s", baseUrl, db), TEST_USERNAME, TEST_PWD);
Statement statement = conn.createStatement()) {
statement.executeUpdate(sql);
} catch (SQLException e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册