Add MySQL JDBC Driver to Eclipse

This tutorial shows you the way to add the latest MySQL JDBC driver to Eclipse. Same steps can be followed to add any other JDBC drivers to Eclipse.

Step 1:
Download and extract the MySQL JDBC connector, from this link: Download Connector/J

Step 2:
Copy the mysql-connector-java-xxx-bin.jar file to any desired folder.

Step 3:
Go to the Window → Preferences in Eclipse.


Step 4:
Expand the Data Management → Connectivity → Driver Definitions and click on the Add button.


Step 5:
In the appeared New Driver Definition dialog, select the MySQL in the vendor filter combo box and select the latest MySQL JDBC Driver from the listed drivers.


Step 6:
Once you have selected the MySQL JDBC Driver, switch to the JAR List tab.


Step 7:
Click on the "
Add JAR/Zip" button or select the existing driver if available and click on the "Edit JAR/Zip" button.

Step 8:
Browse and select JDBC connector JAR file and click OK.


Step 9:
Double check the added driver in the list of available driver definitions and click OK.



Previous
Next Post »

16 comments

Write comments
Sindhu Havaldhar
AUTHOR
March 25, 2017 at 8:29 PM delete

i did everything according to the above mentioned steps but when i add the mySql connector jar file i am not able press ok. ok button is still disabled.

Reply
avatar
Sindhu Havaldhar
AUTHOR
March 25, 2017 at 8:30 PM delete

i did everything according to the above mentioned steps but when i add the mySql connector jar file i am not able press ok. ok button is still disabled. https://uploads.disquscdn.com/images/4f71b170ddb4160f10126a6d7f08f8dd769cbda1df14d6d5cc616cf5ec1576ab.png

Reply
avatar
Gobinath
AUTHOR
March 28, 2017 at 5:54 AM delete

Hi,
Remove the existing mysql-connector-java-5.1.0-bin.jar and try again.

Reply
avatar
Sindhu Havaldhar
AUTHOR
March 30, 2017 at 12:03 PM delete

thank you sir. It worked. But when I try to connect to database through java https://uploads.disquscdn.com/images/8e1ee4a4a4f480cebdfdfebe5c729afdedd7aa77452dc50974bb1b6d7ec4a534.png program it is throwing class not found exception. But when I make another copy of the same program in my home directory and run it from terminal it is running successfully.

CODE:

package com.sindhu.hav;

import java.sql.*;
import java.util.Properties;

public class ConDb
{
// The JDBC Connector Class.
private static String dbClassName = "com.mysql.jdbc.Driver";

// Connection string. emotherearth is the database the program
// is connecting to. You can include user and password after this
// by adding (say) ?user=paulr&password=paulr. Not recommended!

private static final String CONNECTION =
"jdbc:mysql://127.0.0.1/projectRegistery";

public static void main(String args[]) throws
ClassNotFoundException,SQLException
{
//System.out.println(dbClassName);
// Class.forName(xxx) loads the jdbc classes and
// creates a drivermanager class factory
Class.forName(dbClassName);

// Properties for user and password. Here the user and password are both 'paulr'
Properties p = new Properties();
p.put("user","sindhu");
p.put("password","havaldar");

// Now try to connect
Connection c = DriverManager.getConnection(CONNECTION,p);
Statement st= c.createStatement();
ResultSet res=st.executeQuery("select * from users u");
System.out.println("It works !");
if(res.next())
{
do{
System.out.println(res.getString("uname"));
}while(res.next());
}
c.close();
}
}

Reply
avatar
Gobinath
AUTHOR
March 30, 2017 at 3:58 PM delete

Hi,
Check the libraries included in your project. Make sure that MySQL dependencies are listed there.

Reply
avatar
Priya Singh
AUTHOR
March 31, 2017 at 7:15 PM delete

https://uploads.disquscdn.com/images/28f2bb2765324559a9241c1fe476ef538cfc5a086dcf95d780f3f2ebfc1efe98.jpg its showing "A driver already exists with that name. Please provide a unique driver name". what should i do now?

Reply
avatar
Gobinath
AUTHOR
March 31, 2017 at 8:03 PM delete

Check the existing drivers in Stpe 4 and make sure that you do not have an existing MySQL driver there.

Reply
avatar
xyz
AUTHOR
March 31, 2017 at 8:59 PM delete

i already have one. now do i need to remove it and again add it or leave it there as it is?

Reply
avatar
Sindhu Havaldhar
AUTHOR
March 31, 2017 at 10:19 PM delete

no its not there..
https://uploads.disquscdn.com/images/03ae2489e1c3c10826c0bcd2155ea8953d52b7084907edcd766123ff84fc99db.png

Reply
avatar
Sindhu Havaldhar
AUTHOR
March 31, 2017 at 10:22 PM delete

its not there. https://uploads.disquscdn.com/images/03ae2489e1c3c10826c0bcd2155ea8953d52b7084907edcd766123ff84fc99db.png

Reply
avatar
Gobinath
AUTHOR
April 1, 2017 at 6:38 AM delete

That means you have already added it. Just leave is as it is.

Reply
avatar
Gobinath
AUTHOR
April 1, 2017 at 6:43 AM delete

Hi,
This tutorial shows how to add JDBC Driver to Eclipse which is used by Eclipse when you add database connections through Eclipse. In your case, you need to add the JDBC library to your project manually. Follow Step 3 without maven in this article [1] where you need to add the MySQL libraries. Ignore the Hibernate jars if you do not use them.

[1] http://www.javahelps.com/2015/07/hibernate-hello-world-using-annotation.html

Reply
avatar
Sindhu Havaldhar
AUTHOR
April 1, 2017 at 1:00 PM delete

thank you sir.

Reply
avatar
Gobinath
AUTHOR
April 1, 2017 at 4:35 PM delete

You are welcome :-)

Reply
avatar
Nadia
AUTHOR
September 23, 2017 at 5:26 AM delete

Hello. Step 5 when I select MySql I don't have any option in Available Driver Templates. Could you please help me with this.

Reply
avatar
Gilceli Lopes
AUTHOR
October 26, 2017 at 10:48 PM delete

Hello, Thank you so much. It helps me a lot. I follwed every step and it works well, but I am new here and in java programmation, could help me in another problem, please. When I try post my page, this message apear and I don t know how to fix it

org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

Reply
avatar

Contact Form

Name

Email *

Message *