Search code examples
mysqljdbcnetbeansnetbeans-8mysql-connector

Specified Class is not a Driver. Can't add MySQL Connector/J 8.0 to Netbeans 8.0


I can't get MySQL 8.0 jdbc driver set up in Netbeans. Can anyone help?

My Netbeans 8.0 IDE was set up using an older version of the MySQL JDBC Driver, 5.1.23. I upgraded MySQL to 8.0 and am trying to setup a new JDBC Driver in Netbeans because the old driver isn't able to connect to the new DB (*see note at end).

These are the steps I followed.

Step 1: I removed the old mysql driver jar file from D:\Program Files\NetBeans 8.0\ide\modules\ext and copied the new mysql-connector-java-8.0.12.jar file and restarted the IDE.

Step 2: In the Services tab under Databases I right clicked on Drivers and New Driver...

Netbeans Database Drivers

Step 3: In the dialog box that shows up I click the Add... button and I select the new driver jar D:\Program Files\NetBeans 8.0\ide\modules\ext\mysql-connector-java-8.0.12.jar

At this point the Driver Class automatically gets populated with com.mysql.jdbc.Driver and I can't hit the OK button because there's a message Specified class is not a driver (java.sql.Driver)

enter image description here

I tried changing it to com.mysql.cj.jdbc.Driver but it still gave the same message.

I decompiled com.mysql.jdbc.Driver from the jar file and got this:

package com.mysql.jdbc;

import java.io.PrintStream;
import java.sql.SQLException;

public class Driver
  extends com.mysql.cj.jdbc.Driver
{
  public Driver()
    throws SQLException
  {}

  static
  {
    System.err.println("Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.");
  }
}

and for com.mysql.cj.jdbc.Driver I got this

package com.mysql.cj.jdbc;

import java.sql.DriverManager;
import java.sql.SQLException;

public class Driver
  extends NonRegisteringDriver
  implements java.sql.Driver
{
  public Driver()
    throws SQLException
  {}

  static
  {
    try
    {
      DriverManager.registerDriver(new Driver());
    }
    catch (SQLException E)
    {
      throw new RuntimeException("Can't register driver!");
    }
  }
}

So com.mysql.jdbc.Driver extends com.mysql.cj.jdbc.Driver which implements java.sql.Driver so I don't know what the error is all about.

Anyone have any idea how to resolve this? I tried a 6.0 driver and got the same error. The 5 driver works but can't connect to DB.

  • Side note. with the old 5 driver I was getting ClassCastException when trying to connect to database. BigInt can't be Cast to Long. When I changed the driver in the application to the new driver that problem went away.

Solution

  • First, I am successfully using mysql-connector-java-8.0.12.jar as the driver for MySQL 8.0 on NetBeans 8.2, so it definitely works:

    mySqlDriver

    I don't see any obvious reason for your problem but there are some things you can try to resolve this:

    • In your New JDBC Driver screenshot NetBeans is naming the driver MySQL (Connector/J driver) (1). Presumably that is because you already have a driver named MySQL (Connector/J driver), and your first screen shot confirms that. Why are you trying to add a second driver for MySQL? If there is no good reason, can you delete the old one, and then try adding the driver again?

    • Check for multiple instances of the 8.0.12 driver, and delete any old MySQL 5.x and MySQL 8.x drivers in your filestore, unless you have good reason to keep any of them.

    • The download page for Connector/J states "We suggest that you use the MD5 checksums and GnuPG signatures to verify the integrity of the packages you download". Did you do that? It's unlikely but possible that you have a corrupt file. Also, note that you must select "Platform Independent" when downloading the driver for Windows.

    • NetBeans might be caching something that's causing this problem. That's just a wild and desperate guess on my part, with no evidence at all to back it up, but you can easily and safely delete the cache to eliminate it as a possibility:

      • Help > About
      • Scroll down and locate the path of the Cache directory.
      • Shutdown NetBeans and delete that directory.
      • Start NetBeans and try again.
    • Check the NetBeans Log for possible insight into the problem:

      • Repeat the attempt to create the driver.
      • View > IDE Log and review the most recent entries in the log.
    • There might be an issue with NetBeans 8.0 since it is fairly old. Is it possible to upgrade to version 8.2 or 9.0?


    Update based on feedback in the comments from the OP:

    The OP reports that the cause of the problem was given by this message in the NetBeans log:

    INFO [org.netbeans.modules.db.explorer.dlg.AddDriverDialog]: Got an
    exception trying to load class com.mysql.jdbc.Driver during search for
    JDBC drivers in driver jar(s): java.lang.UnsupportedClassVersionError:
    com/mysql/jdbc/Driver : Unsupported major.minor version 52.0. Skipping
    this class...
    

    The Connector/J 8.0 driver requires Java 8:

    It is a MySQL driver for the Java 8 platform. For Java 7 or earlier, use Connector/J 5.1 instead.

    So updating the default platform for NetBeans from JDK 7 to JDK 8 in netBeans.conf resolved the issue.