Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    2

    Unanswered: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver

    Hi,

    I am a Tester and do not have much idea of programming and databases. I have the following script that does a connection to the Oracle Database and fetches some some rows and displays them.

    import java.sql.*;
    import java.io.*;
    import java.util.*;

    public class SampleOraTest
    {

    public static void main(String args[]) {
    String userid="user";
    String passwd="password";
    String driver ="oracle.jdbc.OracleDriver";
    Connection ctn=null;
    ResultSet rs=null;

    try
    {
    Class.forName(driver);
    }catch(Exception e){
    e.printStackTrace();

    }

    try
    {
    ctn = DriverManager.getConnection(url, userid, passwd);
    }catch(Exception e){
    e.printStackTrace();
    }

    Statement statement = null;

    try
    {
    statement=ctn.createStatement();
    rs=statement.executeQuery("select * from customer");
    }catch(Exception e){
    e.printStackTrace();
    }

    try
    {

    while(rs.next())
    {
    System.out.println("CUSTID ="+rs.getString("CUSTID"));
    System.out.println("CUSTNAME ="+rs.getString("CUSTNAME"));
    System.out.println("CUSTADDR ="+rs.getString("CUSTADDR"));
    System.out.println("CUSTPHONE ="+rs.getString("CUSTPHONE"));
    System.out.println("CUSTEMAIL ="+rs.getString("CUSTEMAIL"));
    System.out.println("CUSTSTAT ="+rs.getString("CUSTSTAT"));

    }
    }catch(Exception e){
    System.out.println("While catch");
    e.printStackTrace();
    }


    }


    }


    The Script works fine and is compiled correctly. But there is a problem with the connection with the database. I get the following error:

    java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 198)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 62)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:322)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:130)
    at SampleOraTest.main(SampleOraTest.java:20)
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager .java:532)
    at java.sql.DriverManager.getConnection(DriverManager .java:171)
    at SampleOraTest.main(SampleOraTest.java:30)
    java.lang.NullPointerException
    at SampleOraTest.main(SampleOraTest.java:40)
    While catch
    java.lang.NullPointerException
    at SampleOraTest.main(SampleOraTest.java:50)

    I know that I have to set the CLASSPATH and PATH variables such that my Oracle Driver is recognised. But I do not know what to put in my CLASSPATH. I have put the following in the CLASSPATH, but still I get the same errors:

    CLASSPATH:
    C:\TIBCO\TIBRV\LIB\tibrvj.jar;D:\oratest\SampleOra Test.jar;D:\s-tsi-tests\2.0\root\local\common\smapper\lib\smapper.ja r;E:\OraHome1\jdbc\lib\classes12.jar;E:\OraHome1\j dbc\lib\nls_charset12.jar;E:\OraHome1\jdbc\lib\cla sses12.zip;

    PATH:
    E:\OraHome1\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\tibco\tra\1.0\bin;%S ystemRoot%\system32;%SystemRoot%;%SystemRoot%\Syst em32\Wbem;d:\Program Files\Perforce;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\TIBCO\TIBRV\BIN;E:\OraHome 1\jdbc\lib;E:\OraHome1\bin;E:\OraHome1\jdk\bin;E:\ OraHome1\jdk\jre\bin;E:\OraHome1\jdk\jre\lib;E:\Or aHome1\jdk\lib;E:\OraHome1\jlib;E:\OraHome1\jsp\li b;E:\OraHome1\sqlj\lib;E:\OraHome1\ord\jlib;


    My Oracle Installtion is in E:\OraHome1 and the jdbc\lib directory is in E:\OraHome1\jdbc\lib. This directory consists of the classes12.zip,classes12.jar..etc files.

    Please Help.

    best regards,
    Rajasekhar

  2. #2
    Join Date
    Nov 2003
    Location
    Bangalore,India
    Posts
    51

    Solution for you

    Hi The problem is in the following line
    oracle.jdbc.OracleDriver

    What you need to do is
    oConnection = DriverManager.getConnection("jdbcracle:thin:@xxx.x.x.xx:1521raclesid","username", "password");

    It should work
    Cheers
    Keep things simple as world is already complex

  3. #3
    Join Date
    Nov 2003
    Location
    Bangalore, INDIA
    Posts
    333

    Thumbs up

    Hi,

    Still U get the same error then apply patch 1658250.
    SATHISH .

  4. #4
    Join Date
    Jan 2004
    Posts
    2

    thanks

    Thanks, it worked.

    Now, the connection is OK.
    I used another script in which I used executeUpdate to Drop and Create some tables. It worked fine. But when I use executeUpdate to Insert Rows into the same newly created tables, the rows are not inserted.
    What is the Problem?

    regards,
    Rajasekhar

Posting Permissions

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