title: Using Java to connect to an Oracle database
body: <p>This Java code compiles fine, but when I try to run it I get:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ClassNotFoundException:
    oracle.jdbc.driver.OracleDriver</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><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);
      }
  }
  </code></pre>
  
  <p>How do I get this to work? I am using Ubuntu 11.04 and JDK 6.</p>
  
  <p>Thanks!</p>