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!

bumbleshoot
  • 1,082
  • 2
  • 17
  • 32

4 Answers4

9

You need the Oracle jars.

You can get them from here.

dcp
  • 54,410
  • 22
  • 144
  • 164
5

If you're using Maven:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0</version>
</dependency>
David Caissy
  • 2,181
  • 5
  • 24
  • 26
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.

David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
1

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

Wottensprels
  • 3,307
  • 2
  • 29
  • 38