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.
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:
17 comments
Write commentsi 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.
Replyi 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
ReplyHi,
ReplyRemove the existing mysql-connector-java-5.1.0-bin.jar and try again.
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.
ReplyCODE:
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();
}
}
Hi,
ReplyCheck the libraries included in your project. Make sure that MySQL dependencies are listed there.
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?
ReplyCheck the existing drivers in Stpe 4 and make sure that you do not have an existing MySQL driver there.
Replyi already have one. now do i need to remove it and again add it or leave it there as it is?
Replyno its not there..
Replyhttps://uploads.disquscdn.com/images/03ae2489e1c3c10826c0bcd2155ea8953d52b7084907edcd766123ff84fc99db.png
its not there. https://uploads.disquscdn.com/images/03ae2489e1c3c10826c0bcd2155ea8953d52b7084907edcd766123ff84fc99db.png
ReplyThat means you have already added it. Just leave is as it is.
ReplyHi,
ReplyThis 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
thank you sir.
ReplyYou are welcome :-)
ReplyHello. Step 5 when I select MySql I don't have any option in Available Driver Templates. Could you please help me with this.
ReplyHello, 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
Replyorg.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
can someone help me my project isn't working I've added the jar file it says but still not working i don't know what to do please help
ReplyEmoticonEmoticon