Netbeans – How To Load Jdbc Driver To Connect To Mysql Database (Java)

How To Add Mysql Connector Jar File In Netbeans – Java

Netbeans – How To Load Jdbc Driver To Connect To Mysql Database (Java)

To download jdbc mysql driver go to – https://dev.mysql.com/downloads/connector/j/

 How To Add Mysql Connector Jar File In Netbeans Java - Downloading Mysql Connector J
How To Add Mysql Connector Jar File In Netbeans Java – Downloading Mysql Connector J


To connect to mysql database using netbeans you need a database connector called MySQL Connector/J.
You need to add mysql connector jar file to the current project so that you can interact with the target database.
To import the connector to the current project:
Step 1. Right click on project.

 How To Add Mysql Connector Jar File In Netbeans Java - Right Click On A Project And Select Properties
How To Add Mysql Connector Jar File In Netbeans Java – Right Click On A Project And Select Properties


Step 2. Select Properties.
Step 3. Select Libraries.
Step 4. Click “add external jars”.

 How To Add Mysql Connector Jar File In Netbeans Java - Slect Libraries Then Add Jar
How To Add Mysql Connector Jar File In Netbeans Java – Slect Libraries Then Add Jar


Step 5. Go to the folder where you have downloaded the file. Select MySQL Connector/J jar file and click ok.

 How To Add Mysql Connector Jar File In Netbeans Java - Locate Mysql Connector J Jar File
How To Add Mysql Connector Jar File In Netbeans Java – Locate Mysql Connector J Jar File

After you select mysql connector j, it’s going to be added under compile time libraries section.

 How To Add Mysql Connector Jar File In Netbeans Java - Mysql Connector J Selected
How To Add Mysql Connector Jar File In Netbeans Java – Mysql Connector J Selected

Now when you go back to the project you will see connector j jar file on libraries section.

How To Add Mysql Connector Jar File In Netbeans Java - Connector Added To Project Libraries
How To Add Mysql Connector Jar File In Netbeans Java – Connector Added To Project Libraries

To check whether the connector has been added to the project use the code below.

package checkmysqlconnector;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Genuine
 */
public class CheckMysqlConnector {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String forName = "com.mysql.cj.jdbc.Driver";
        try {
            Class.forName(forName);
            System.out.println("Driver Loaded Successfully");
        } catch (ClassNotFoundException ex) {
            System.out.println("Driver Failed To Load Successfully");
            System.out.println(ex.getMessage());
        }
    }
    
}

Leave a Reply

Your email address will not be published. Required fields are marked *