Reputation: 15335
I Installed JDK 1.7 and tried to connect to different MySQL database and Connector/J versions. But every time, I'm getting the following error when loading the driver:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at jdbc.JDBC.main(JDBC.java:24)
Caused by: java.lang.RuntimeException: Uncompilable source code - com.mysql.jdbc.NonRegisteringDriver is not abstract and does not override abstract method getParentLogger() in java.sql.Driver
at com.mysql.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:69)
... 3 more
Which MySQL driver version is compatible with JDK 1.7?
Upvotes: 1
Views: 5589
Reputation: 719229
The exception message says this:
"Caused by: java.lang.RuntimeException: Uncompilable source code - com.mysql.jdbc.NonRegisteringDriver is not abstract and does not override abstract method getParentLogger() in java.sql.Driver"
I think that the problem is that you (or someone else) have/has attempted to build the JDBC driver from source code and not noticed that there were compilation errors, and assembled the resulting broken ".class" files into a JAR file.
The standard Connector/J driver JAR files from the MySQL website should work with Java 7. Certainly, I've never experienced any problems like this with them.
I'm more inclined to believe the evidence that I can see in the Exception message than your assurance that everything is "perfect":
Are you sure that you are using a Connector/J JAR file that you downloaded from the MySQL Website?
Did you check that MD5 checksum to make sure that you got the real thing?
If you built from source, did you read the stuff in the docs/readme.txt about the JRE versions required to build correctly?
Do you have some other (broken) copy of the drivers on your application's classpath?
Upvotes: 3
Reputation: 5315
"Caused by: java.lang.RuntimeException: Uncompilable source code -
com.mysql.jdbc.NonRegisteringDriver is not abstract and does not override
abstract method getParentLogger() in java.sql.Driver"
The method getParentLogger()
was introduced to the Driver
interface in Java 1.7.
Find a MySQL driver that supports Java 1.7 or switch back to Java 1.6.
Edit: Additional info:
I tested JDK 1.7.10 and a driver Jar named: mysql-connector-java-5.1.6-bin.jar
Using the following code:
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException, SQLException {
System.out.println("Java version: "
+ System.getProperty("java.version"));
Driver driver = (Driver) Class.forName("com.mysql.jdbc.Driver")
.newInstance();
System.out.println("JDBC driver: " + driver.getMajorVersion() + "."
+ driver.getMinorVersion());
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/DBNAME", "user", "pass");
System.out.println("Connection: " + connection.getClass().getName());
}
It gives the following output:
Java version: 1.7.0_10
JDBC driver: 5.1
Connection: com.mysql.jdbc.JDBC4Connection
Possibly you have also a problem with the JDK/JRE Installation. When installing the JDK, it wants to update SQL drivers.
You might give it a try to uninstall and re-install the JDK.
Upvotes: 2