Skip to content

Commit

Permalink
add check
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing committed Mar 20, 2023
1 parent 71b955d commit 4ec231e
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,22 @@ private static Connection doConnect(String driver, String url, String username,
}

public static String extractDatabaseFromUrl(String url) {
if (url == null || url.isEmpty()) {
throw new RuntimeException("Null or Empty JDBC URL supplied: " + url);
if (!hasDatabase(url)) {
throw new RuntimeException("Invalid JDBC URL supplied: " + url);
}
return url.substring(url.lastIndexOf("/") + 1, url.indexOf("?"));
}

String urlWithoutParams;
if (url.contains("?")) {
urlWithoutParams = url.substring(0, url.indexOf("?"));
} else {
urlWithoutParams = url;
public static boolean hasDatabase(String url) {
if (url == null || url.isEmpty()) {
return false;
}

return urlWithoutParams.substring(urlWithoutParams.lastIndexOf("/") + 1);
int index = url.indexOf("://");
if (index == -1) {
return false;
}
index = url.indexOf("/", index + 3);
return index != -1;
}

private static TablesResponse getAllTablesAndViews(Statement statement, String database) throws SQLException {
Expand Down

0 comments on commit 4ec231e

Please sign in to comment.