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.


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:


    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.