Bug #87600 Connector throws 'Malformed database URL' on non mysql connection-urls
Submitted: 30 Aug 2017 9:02 Modified: 25 Jun 2018 20:28
Reporter: Praml Roland Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:6.0.6 OS:Any
Assigned to: CPU Architecture:Any

[30 Aug 2017 9:02] Praml Roland
Description:
When trying to connect to an oracle database, and the mysql-connector is also in classpath, it throws a 'Malformed database URL' while the 'DriverManager.getConnection' probes the different drivers. 

The connection URL for oracle is 'jdbc:oracle:thin:@127.0.0.1:1521:xe' - which is unparseable for mysql.

(Similar to https://bugs.mysql.com/bug.php?id=82896)

How to repeat:
Testcode:

conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe", "user", "pass");

Expected behaviour:
- Connect successfully (if oracle driver is in classpath)
- Get "No suitable driver found" - if driver is not in classpath

Current behaviour:
- mysql-connector fails with "Malformed database URL" and makes it impossible to connect to oracle db

Workaround:
- use version 5.1.43

Stack Trace:

java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.core.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:526)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:505)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:479)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:489)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:72)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:124)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:224)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at io.ebean.TestBase.main(TestBase.java:11)
Caused by: com.mysql.cj.core.exceptions.UnableToConnectException: Cannot load connection class because of underlying exception: com.mysql.cj.core.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:93)
	... 4 more
Caused by: com.mysql.cj.core.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
	at com.mysql.cj.core.conf.url.ConnectionUrlParser.parseConnectionString(ConnectionUrlParser.java:134)
	at com.mysql.cj.core.conf.url.ConnectionUrlParser.<init>(ConnectionUrlParser.java:124)
	at com.mysql.cj.core.conf.url.ConnectionUrlParser.parseConnectionString(ConnectionUrlParser.java:113)
	at com.mysql.cj.core.conf.url.ConnectionUrl.getConnectionUrlInstance(ConnectionUrl.java:192)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:194)
	... 3 more

Suggested fix:
NonRegisteredDriver.connect should not try to parse other driver's urls and return "null" immediately, if url does not start with "jdbc:mysql:" (Normal jdbc connection) or "mysqlx:" (XDEVAPI_SESSION)
[30 Aug 2017 13:32] Chiranjeevi Battula
Hello Roland,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[25 Jun 2018 20:28] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 8.0.12 changelog:

"When an application tried to connect to a non-MySQL database through some JDBC driver and Connector/J happened to be on the class path also, Connector/J threw a SQLNonTransientConnectionException, which prevented the application from connecting to its database. With this fix, Connector/J returns null whenever a connection string does not start with jdbc:mysql or jdbc:mysqlx , so connections to non-MySQL databases are not blocked."
[25 Jun 2018 20:39] Daniel So
Posted by developer:
 
Corrected the changelog entry to the following:

"When an application tried to connect to a non-MySQL database through some
JDBC driver and Connector/J happened to be on the class path also,
Connector/J threw a SQLNonTransientConnectionException, which prevented the
application from connecting to its database. With this fix, Connector/J
returns null whenever a connection string does not start with jdbc:mysql: or
mysqlx:, so connections to non-MySQL databases are not blocked."