Results 1 to 2 of 2
  1. #1
    Navatha is offline Member
    Join Date
    Sep 2010
    Posts
    11
    Rep Power
    0

    Default JDBC connection failed to oracle 10g can anyone help

    iam trying to connect to oracle 10g using this code but iam unable to connect please help me
    package jdbcstatements;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;



    public class JDBCConnection {

    public static void main(String[]args)
    {

    try {

    Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
    String url="jdbc:oracle:thin:@localhost:1521:orcl";

    Connection con=DriverManager.getConnection( url, "scott", "tiger");
    System.out.println("connection created");

    Statement db_statement = con.createStatement();
    db_statement.executeUpdate
    ("create table employee { int id, char(50) name };");
    con.commit();
    ResultSet result = db_statement.executeQuery
    ("select * from employee");
    while (result.next() )
    {
    // Use the getInt method to obtain emp. id
    System.out.println ("ID : " + result.getInt("ID"));

    // Use the getString method to obtain emp. name
    System.out.println ("Name : " + result.getString("Name"));
    System.out.println ();
    }

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

    }
    }
    the error iam getting ids

    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at jdbcstatements.JDBCConnection.main(JDBCConnection. java:17)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,165
    Rep Power
    20

    Default

    Your Oracle driver jar file is not on the runtime classpath.
    How you run this will determine how it gets fixed.

    As a note, code should be posted in code tags to retain formatting.
    And do not eat exceptions. At the very least printStackTrace().
    And finally you should close your resources (resultset, stetamenet, connection) in a finally block.

Similar Threads

  1. JDBC with Netbeans/Oracle
    By sehudson in forum Advanced Java
    Replies: 1
    Last Post: 03-11-2010, 10:26 AM
  2. JDBC Oracle Connection
    By Bean in forum New To Java
    Replies: 13
    Last Post: 11-06-2009, 09:06 PM
  3. oracle JDBC java
    By silia_motor in forum JDBC
    Replies: 4
    Last Post: 05-10-2009, 10:37 AM
  4. Jdbc Driver For Oracle
    By Swamipsn in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 05:31 AM
  5. Oracle and JDBC
    By Eric in forum JDBC
    Replies: 3
    Last Post: 08-11-2007, 09:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •