Reputation: 163
I'm looking for resolve problem with eclipse, im trying to connect to MySQL via ODBC im using java 1.7, and the same code in NetBeans, and Eclipse,
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Gtable","root","");
In NetBeans it works fine but in Eclipse returns
Exception in thread "main" java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at testdb2.testd.main(testd.java:11)
How can i fix it ?
it did not help
Im using this now,
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("sun.jdbc.odbc.JdbcOdbcDriver found");
} catch (ClassNotFoundException cnfe) {
System.out.println("Error: sun.jdbc.odbc.JdbcOdbcDriver not found");
}
And it returns jdbcodbc not found, where can i get that ?
Upvotes: 0
Views: 2631
Reputation: 123494
The issue with the Eclipse project was that it was actually running under Java 8, so the JDBC-ODBC Bridge was not available. Changing the run configuration to use a Java 7 JRE solved the problem.
Upvotes: 2
Reputation: 77
If you want to do this correctly, add a folder called lib to your current project. Download the jar for the driver and drag this jar from your file explorer in your lib folder in eclipse. After this, right click your project folder -> java build path, look for the libraries tab and click add jars. Browse to your jar in the lib folder and click OK. After this click ok again. This should work :)
Try this:
Class.forName("com.mysql.jdbc.Driver");
If this doesn't work, you probably gave the wrong path. Try searching in your referenced libraries in the package explorer view. Just expand the jar and look for driver.class. If this is to much work, your could try searching with shift + ctrl + r. adjust your filter to your needs. You need to search for the path of driver.class
I also suggest you not to use root and give it a strong password
Upvotes: 0
Reputation: 31
You should open project property (alt+Enter), open menu "Deploy Assembly", and set libraries folder, where you have jdbc driver. Something like this:
Upvotes: -1