Getting MySQL error stack trace on Oracle JDBC Connection

前端 未结 1 1225
礼貌的吻别
礼貌的吻别 2020-12-21 10:55

I am facing very odd error while making Oracle JDBC connection using a connection string. I am giving username as \"sys\"(which should be sys as sysdba) and ideally, it shou

相关标签:
1条回答
  • 2020-12-21 11:43

    This error occurs with MySQL Connector/J 8 version 8.0.11 or earlier (and the never released MySQL Connector/J 6 versions). You need to upgrade to 8.0.12 or higher (current latest version is 8.0.17, see https://dev.mysql.com/downloads/connector/j/).

    From the Connector/J 8.0.12 release notes:

    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. (Bug #26724154, Bug #87600)

    See also https://bugs.mysql.com/bug.php?id=87600

    As background, normally, JDBC drivers that don't support a specific URL (eg based on the sub-protocol after jdbc:), should return null, and an exception should only be thrown if a URL is for the driver, but there is a problem with the URL or with creating a connection.

    However, even with this bug in the MySQL Connector/J driver, you would still be able to connect to an Oracle database, as DriverManager will try each driver until it is able to open a connection. If no drivers were able to connect, it will throw the first exception thrown by any driver, or - if all drivers returned null - it will throw a "No suitable driver found" exeption.

    In this case it looks like MySQL was the driver tried before the Oracle driver, and as you expect your Oracle connection to fail as well, it just happens to throw the MySQL exception as that was the first exception.

    Long story short, update your MySQL Connector/J.

    0 讨论(0)
提交回复
热议问题