[BUG]Fix the bug of port identification failure when connecting Oracle with Sid mode (JDBC: Oracle: thin: @ < host >: < port > / < Sid >) (#4320)

* [BUG]Fix the bug of port identification failure when connecting Oracle with Sid mode (JDBC: Oracle: thin: @ < host >: < port > / < Sid >)

Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
AirTrioa 2020-02-05 20:30:03 +08:00 committed by GitHub
parent fa1e60f411
commit 69d238e613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -136,6 +136,22 @@ public class OracleURLParser extends AbstractURLParser {
private String[] splitDatabaseAddress(String address) {
String[] hostSegment = address.split(":");
return hostSegment;
if (hostSegment.length == 1 && super.fetchDatabaseNameFromURL().contains("/")) {
String[] portAndDatabaseName = super.fetchDatabaseNameFromURL().split("/");
return new String[]{hostSegment[0], portAndDatabaseName[0]};
} else {
return hostSegment;
}
}
@Override
protected String fetchDatabaseNameFromURL() {
String databaseName = super.fetchDatabaseNameFromURL();
if (databaseName.contains("/")) {
String[] portAndDatabaseName = databaseName.split("/");
return portAndDatabaseName[1];
} else {
return databaseName;
}
}
}

View File

@ -82,6 +82,14 @@ public class URLParserTest {
assertThat(connectionInfo.getDatabasePeer(), is("localhost:1522"));
}
@Test
public void testParseOracleSID() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:1522/orcl");
assertThat(connectionInfo.getDBType(), is("Oracle"));
assertThat(connectionInfo.getDatabaseName(), is("orcl"));
assertThat(connectionInfo.getDatabasePeer(), is("localhost:1522"));
}
@Test
public void testParseOracleServiceName() {
ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@//localhost:1521/orcl");