Skip to content

[Java] JDBC connector throws SQLException instead of returning null for unsupported URLs #661

Description

@mamin11

Description

software.amazon.dsql.jdbc.DSQLConnector.connect() currently throws SQLException for URLs that are not accepted by the Aurora DSQL JDBC connector.

Per the java.sql.Driver.connect contract, a driver should return null when it realizes it is the wrong driver for the URL, so DriverManager can try the next registered driver.

Version

Observed on latest JDBC tag: java/jdbc/v1.5.0.

Steps to reproduce

  1. Register/load the Aurora DSQL JDBC connector.
  2. Call:
Properties props = new Properties();
props.setProperty("user", "testuser");

Connection conn =
    new DSQLConnector().connect("jdbc:postgresql://localhost:5432/postgres", props);

Actual behavior

connect() throws: SQLException: URL must be a valid Aurora DSQL URL

Expected behavior

connect() should return null because acceptsURL(...) returns false for that URL. This allows DriverManager to continue trying other registered JDBC drivers.

Reference

java.sql.Driver.connect specifies that a driver should return null when it is the wrong driver for the URL, and throw SQLException when it is the right driver but cannot connect. https://docs.oracle.com/cd/E13222_01/wls/docs/classdocs/java.sql.Driver.html

Proposed fix

At the start of DSQLConnector.connect():

if (url == null) {
    throw new SQLException("URL is null");
}
if (!acceptsURL(url)) {
    return null;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions