Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java to connect to an Oracle database

Tags:

java

oracle

jdbc

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!

like image 505
bumbleshoot Avatar asked Dec 01 '22 22:12

bumbleshoot


1 Answers

You need the Oracle jars.

You can get them from here.

like image 90
dcp Avatar answered Dec 14 '22 23:12

dcp