4

This Java code compiles fine, but when I try to run it I get:

Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Here is my code:

import java.sql.*;

public class TestConnection {

    public static void main(String[] args) throws Exception {
        //connect to database
        Class.forName("oracle.jdbc.driver.OracleDriver");
        String serverName = "000.000.000.000";
        String portNumber = "1521";
        String sid = "abcd";
        String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
        String username = "user";
        String password = "pass";
        Connection conn = DriverManager.getConnection(url, username, password);
    }
}

How do I get this to work? I am using Ubuntu 11.04 and JDK 6.

Thanks!

2
  • 3
    You need to download the Oracle JDBC driver and put it on your classpath. Commented Jun 18, 2012 at 18:50
  • do you have appropriate jar file? Commented Jun 18, 2012 at 18:50

4 Answers 4

9

You need the Oracle jars.

You can get them from here.

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

3 Comments

You'll probably want to grab ojdbc6.jar from that link.
It says: ojdbc6.jar (2,714,189 bytes) - Classes for use with JDK 1.6. But I have JDK 6??
5

If you're using Maven:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0</version>
</dependency>

2 Comments

is it still present in mvn repo ?
It's not public right now. I had to register previously in the Oracle Maven Repository. More info here: link
3

Add ojdbcXX.jar-where XX is version number-to Java build path of your project. Aside from the classpath issue, requesting "oracle.jdbc.driver.OracleDriver" is deprecated. For a long time it has been recommended to use: "oracle.jdbc.OracleDriver". For some more recent driver versions, the former will not even work.

2 Comments

Why that jar? And where can I get it?
Oh no sorry you would use ojdbc6.jar as this is for java 6. (1.6 is the same as 6 naming conventions for java changed). The one i referenced was for java 1.4!
1

Also, you have to add those jars to your project. @Netbeans, you can easily do that at the project-properties

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.