0

I am getting java.lang.ClassNotFoundException on loading sun.jdbc.odbc.JdbcOdbcDriver using Class.forName().

I am using MySQL as Data Source and I have added Data Source Name in ODBC Data Source Administrator (on Windows 8).

Here is the code:

class Connect {
     check() {
       try {

           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

       } catch (ClassNotFoundException e) {
           e.printStackTrace();
       }
    }
}

Output:

java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
7
  • 3
    The jdbc-odbc bridge has been removed in Java 8. Commented Sep 17, 2014 at 14:12
  • did you try to Test connection in ODBC Data Source Administrator after configuring? Commented Sep 17, 2014 at 14:12
  • @ElliottFrisch then how to connect to Database? Commented Sep 17, 2014 at 14:14
  • Use a Type-4 JDBC driver. Commented Sep 17, 2014 at 14:15
  • @ElliottFrisch I tried using Class.forName("com.mysql.jdbc.Driver") but i am getting same error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Commented Sep 17, 2014 at 14:28

2 Answers 2

1

Are you using Java 8? The class is no longer present there (more info). You could install Java 7 if you need to use it.

Sign up to request clarification or add additional context in comments.

6 Comments

How to connect to Database by using Java 8?
A JDBC driver exists for MySQL, use that instead. Here is an example: tutorialspoint.com/jdbc/jdbc-sample-code.htm
I tried using Class.forName("com.mysql.jdbc.Driver") but i am getting same error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
You need to download the driver from here: dev.mysql.com/downloads/connector/j and add it as a dependency to your project.
How to add it as dependency to project? Do i need to import it? How?
|
0

This happened to me once, and what i did was importing the mysql jdbc library that came with the product when i downloaded it, after that i used the driver as it is explained in the page:

http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-connect-drivermanager.html

hope this could help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.