The java.sql.DriverManager
will ask each registered driver to create a connection with the JDBC url until one driver either returns a (non-null) java.sql.Connection
or throws an SQLException
.
From JDBC 4.2 section 9.2 The Driver interface:
When the DriverManager
is trying to establish a connection, it calls that driver's connect
method and passes the driver the URL. If the Driver
implementation understands the URL, it will return a Connection
object or throw a SQLException
if a connection cannot be maded to the database. If the Driver
implementation does not understand the URL, it will return null
.
From the Driver.connect
API doc:
Attempts to make a database connection to the given URL. The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the JDBC driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn.
The driver should throw an SQLException
if it is the right driver to connect to the given URL but has trouble connecting to the database.
So a compliant JDBC driver must return null
when it is asked to create connection for a JDBC URL it doesn't recognize/support. Only when the URL is supported (eg because the prefix matches the driver), is a driver allowed to throw an SQLException
(eg when there is a syntax error in the rest of the JDBC URL, or if the connection cannot be established).
So the com.treasure_data.jdbc.TreasureDataDriver
is misbehaving because it throws an SQLException
for an URL it doesn't recognise; you need to file a bug report with the author of that driver.