[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:
parent
fa1e60f411
commit
69d238e613
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in New Issue