Solution to Errors that occur while connecting NetBeans and MySQL

Errors that might appear

If you are getting any of the following errors while connecting with MySQL server in NetBeans:

Unable to load authentication plugin ‘caching_sha2_password’ (as shown in below figure)

Or you are getting the following error:

Access denied for user ‘root’@’localhost’ (using password: YES) as shown below:

Or you are getting the following error:

Java.math.BigInteger cannot be cast to java.lang.Long (see below figure)

Reason for these Errors

These errors indicate that the MySQL Java connector is incorrect. Basically NetBeans installs a default MySQL Java driver that you can see in Services tab:

This default MySQL connector provided by NetBeans may not match with the version of the MySQL server that is installed on your computer.

So, we need to install the correct MySQL java connector. To do so, you have to find out what version of MySQL server is installed on your computer and accordingly download and install the MySQL Java connector. For example if I have MySQL version 8.0.15, installed on my machine, then I should have the Connector/J 8.0.15 version installed on my machine.

You can search the net for the compatible MySQL Java connector or you can install it via your MySQL installer too. If you have downloaded the required MySQL Java Connector or have installed it via MySQL installer, skip the following section and go directly to Connecting Correct MySQL Java Connector in NetBeans IDE section.

Installing MySQL Java Connector by MySQL Installer

I assume that you have installed NetBeans on your machine. If not, download it from the following link, https://netbeans.org/downloads/8.2/. On double clicking the downloaded executable file, NetBeans IDE 8.2 will be installed on your machine.

Also, I assume that you have installed, MySQL on your machine by downloading the MySQL installer community file from the following link, https://dev.mysql.com/downloads/windows/installer/8.0.html.

While installing the MySQL server you will be asked for the root’s password.  Write the password somewhere as it will be required while connecting NetBeans with MySQL

While installing MySQL, you will be prompted to install MySQL Java connector, do install it too.

If you have not installed MySQL Java connector while installing MySQL server, you can install it later also by following the below given steps:

Invoke MySQL Installer Community on your machine.  Type MySQL installer on your Start and it will pop up as shown below:

The MySQL Installer window will pop up showing the products that are already installed on your machine along with the provision to add more products, delete or modify the existing products as shown in below figure

To install MySQL Java connector, click on Add button on the right. You get a dialog box as shown in below figure. The left pane will show the list of available products that can be installed. Expand the Connector/J node. You will get a node, Connector/J 8.0 below that node with a sub node, Connector/J 8.0.15 – X86 . Click that sub node and click right arrow button to add the connector to the right pane (Product/Features to Be Installed). Thereafter click on Next button to initiate the installation of the selected connector

You will get a dialog showing the product that will be installed (as shown in below figure). You can see the product, Connector/J 8.0.15 that is ready to be installed. Click the Execute button to begin the installation.

The MySQL Java connector files will be copied and installed on your machine. The status will display, “Complete” to indicate that connector is successfully installed on your computer (see below figure). Click Next button to move further.

The next dialog displays the message that the installation procedure of the selected products is completed. Click Finish button to confirm. Close the MySQL installer community wizard.

Connecting Correct MySQL Java Connector in NetBeans IDE

Once, we have the connector that matches with the version of the MySQL server installed on our machine, we need to connect it in NetBeans IDE too. So launch NetBeans IDE and open Services tab. Expand the Drivers node to see the list of drivers that are auto installed for us. The current MySQL (Connector/J driver) is the one that is provided by NetBeans IDE by default. We need to delete this and  specify the connector that we installed in above section. So, right click the MySQL (Connector/J driver) node and select the Delete option to delete the current connector (see below figure)

After deleting the default connector from the Drivers node, right click on the Drivers node and select “New Driver” option to link the connector that we installed in above section.

You will get a dialog box to specify the new JDBC Driver. Click on the Add button and select the jar file of the Connector that we installed in above section. The default location where the driver is usually installed is “C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.15.jar”. Select the jar file. The Driver class and Name text boxes in the dialog box are auto filled by default. Leaving the rest of boxes at their default values, click the OK button.

The MySQL (Connector/J driver) node will appear under Drivers node but this time it is pointing at the correct Java MySQL connector. Now you can easily connect the MySQL Server to Java by right clicking on the MySQL Server at localhost:3306 [root] node under Databases and select Start option. You will prompted to enter Administrator Password as shown below. Here you need to enter root’s password that you entered while installing MySQL server.

After entering the correct root’s password, the MySQL server will be connected to the localhost as shown below:

 

Leave a Comment