diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java index 3fb70106a..7c9b46052 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java @@ -216,7 +216,7 @@ public JdbcDriver() {} @Override public Connection connect(String url, Properties info) throws SQLException { - if (url != null && url.startsWith("jdbc:cloudspanner")) { + if (url != null && (url.startsWith("jdbc:cloudspanner") || url.startsWith("jdbc:spanner"))) { try { Matcher matcher = URL_PATTERN.matcher(url); Matcher matcherExternalHost = EXTERNAL_HOST_URL_PATTERN.matcher(url); @@ -271,7 +271,7 @@ private String appendPropertiesToUrl(String url, Properties info) { @Override public boolean acceptsURL(String url) { - return URL_PATTERN.matcher(url).matches(); + return URL_PATTERN.matcher(url).matches() || EXTERNAL_HOST_URL_PATTERN.matcher(url).matches(); } @Override diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java index b4ae04f56..494233faf 100644 --- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java +++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDriverTest.java @@ -135,13 +135,14 @@ public void testRegister() throws SQLException { @Test public void testConnect() throws SQLException { - try (Connection connection = - DriverManager.getConnection( - String.format( - "jdbc:cloudspanner://localhost:%d/projects/some-company.com:test-project/instances/static-test-instance/databases/test-database;usePlainText=true;credentials=%s", - server.getPort(), TEST_KEY_PATH))) { - assertThat(connection.isClosed()).isFalse(); - } + for (String prefix : new String[] {"cloudspanner", "spanner"}) + try (Connection connection = + DriverManager.getConnection( + String.format( + "jdbc:%s://localhost:%d/projects/some-company.com:test-project/instances/static-test-instance/databases/test-database;usePlainText=true;credentials=%s", + prefix, server.getPort(), TEST_KEY_PATH))) { + assertThat(connection.isClosed()).isFalse(); + } } @Test(expected = SQLException.class) @@ -215,6 +216,17 @@ public void testLenient() throws SQLException { } } + @Test + public void testAcceptsURL() throws SQLException { + JdbcDriver driver = JdbcDriver.getRegisteredDriver(); + assertTrue( + driver.acceptsURL( + "jdbc:cloudspanner:/projects/my-project/instances/my-instance/databases/my-database")); + assertTrue( + driver.acceptsURL( + "jdbc:spanner:/projects/my-project/instances/my-instance/databases/my-database")); + } + @Test public void testJdbcExternalHostFormat() { Matcher matcherWithoutInstance =