未验证 提交 69d238e6 编写于 作者: A AirTrioa 提交者: GitHub

[BUG]Fix the bug of port identification failure when connecting Oracle with...

[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's avatar吴晟 Wu Sheng <wu.sheng@foxmail.com>
上级 fa1e60f4
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册