Results 1 to 11 of 11
  1. #1
    ehickey is offline Member
    Join Date
    Aug 2009
    Location
    Houston, tx
    Posts
    4
    Rep Power
    0

    Default ClassNotFoundException: oracle.jdbc.driver.OracleDriver

    I recently started working with Java (after years of .Net) and one of the first things I need to do is connect to a database (in this case, Oracle).

    Looking around online, it looks like the standard approach is to use JDBC and grab an Oracle JDBC driver - which I promptly did. Specifically, I pulled down ojdbc6.jar (since I'm running jdk6), and tried one of the simpler examples I saw online.

    It didn't work.

    I went back and read online docs, tutorials, and even posts from here - they were all informative, but didn't say anything about the actual installation process (or made it sound like I have to actually install Oracle itself on this workstation in order to access a remote Oracle db). Feeling like a neanderthal, I decided I should just give up and ask.

    The key issue I'm having is that "oracle.jdbc.driver.OracleDriver" is not recognized. Specifically:
    Class.forName("oracle.jdbc.driver.OracleDriver");
    returns a NoClassDefFoundError exception.

    I tried other .jar files (and learned what a .jar was in the process), toyed with my classpath for a couple of grueling hours, and cursed technology in between sobs.

    My classpath, as it is now, reads as follows:
    ".; c:\java; c:\java\ojdbc6.jar"

    The specific error reads as follows:
    ----------
    > java oracle.jdbc.OracleDriver
    Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver
    Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
    at java.net.TooDumbToMakeItWork(Unknown Source)
    Could not find the main class: oracle.jdbc.driver.OracleDriver. Program will exit.
    ----------

    I've also tried variations of that class path, reordering them and leaving parts out, mostly because I have no idea what else to do.

    The installation process was mostly to download that .jar file and drop it into the directory I was working from (and setting classpath to point to it). I also tried other .jar files, though I have no idea if it's seeing them at all.

    However, if I do this:
    > java -jar ojdbc6.jar
    It responds with this:
    Oracle 11.1.0.7.0-Production JDBC 4.0 compiled with JDK6


    So... any suggestions? Is this just a matter of me blatantly misunderstanding the basic mechanics of Java? Is there a critical step in the installation that I've left out?

  2. #2
    ehickey is offline Member
    Join Date
    Aug 2009
    Location
    Houston, tx
    Posts
    4
    Rep Power
    0

    Default

    I guess I should point out that I'm running Windows XP, have JDK6 installed, and I have no clue what "Oracle Home" is - unless I'm supposed to install something extra that no one mentions explicitly. :)

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    How are you supplying that classpath to your program? What command are you typing to run it?

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Check ur class path whether class12.zip is there or not
    Ramya:cool:

  5. #5
    ehickey is offline Member
    Join Date
    Aug 2009
    Location
    Houston, tx
    Posts
    4
    Rep Power
    0

    Default

    r035198x:
    If you mean how I'm getting the ".; c:\java; c:\java\ojdbc6.jar" classpath, that's in my CLASSPATH environment variable (on windows), and can be verified with the SET command. I know it's being used because if I remove c:\java it no longer finds my classes. The classes I'm working on are also in that directory (along with the drivers).

    I've read online that the command "java oracle.jdbc.OracleDriver" is sufficient to verify that the driver is being recognized (though it might complain about a missing main() method).

    The line in my actual code that produces the error is:
    Class.forName("oracle.jdbc.driver.OracleDriver");

    The only import I'm using is "import java.sql.*;". As far as I've been able to tell that's the only relevant import to use.


    RamyaSivakanth:

    Everything I've read says that class12 is purely for Java 1.2, and that ojdbc6.jar replaces it for jdk6 (I also ended up adding ojdbc5.jar in there just in case).

    Are there any other files I need to add to make this work? DLL's, etc? As far as I can tell the "JDBC" system itself is built into the jdk (and java.sql is present), it just won't recognize that I have the driver. Am I supposed to use class12.zip even though I'm using the 1.6 (or 6, whichever) jdk?

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Try passing that path to the java command for running the class as the -classpath option.

  7. #7
    ehickey is offline Member
    Join Date
    Aug 2009
    Location
    Houston, tx
    Posts
    4
    Rep Power
    0

    Default

    Same result:
    ------------------------------------------------------------
    C:\java>java TestingOracle -classpath /java/ojdbc6.jar

    Exception in thread "main" 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.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at TestingOracle.main(TestingOracle.java:14)
    -------------------------------

    A few questions:

    * is that Jar alone enough to provide the full class "oracle.jdbc.driver.OracleDriver"? And is that the correct class?

    * is there something I have to do to "activate" the .Jar?

    * if the Jar is good, shouldn't "jar -x ojdbc6.jar" or "jar -t ojdbc6.jar" produce a response (instead of just sitting there, doing nothing)?

    * is there a way for me to look inside of the jar file, to see what's actually inside?

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You can extract it using
    jar xvf jarfinename.jar

  9. #9
    AnuragGarg is offline Member
    Join Date
    Feb 2010
    Location
    Ottawa, ON, Canada
    Posts
    1
    Rep Power
    0

    Default

    You should be using:
    Class.forName("oracle.jdbc.OracleDriver");

    The older class-package "oracle.jdbc.driver.OracleDriver" has been deprecated for quite some time, and has been removed from the JDBC driver JAR.

  10. #10
    ScottThornley is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by AnuragGarg View Post
    You should be using:
    Class.forName("oracle.jdbc.OracleDriver");

    The older class-package "oracle.jdbc.driver.OracleDriver" has been deprecated for quite some time, and has been removed from the JDBC driver JAR.
    (Apologies in advance for shouting)

    BLESS YOU !!!!

    I was in the exact same predicament as ehickey.

    NONE, and I repeat, none of the examples I've seen online yesterday and today, are up to date. Many of them refer to classes12.zip, none refer to ojdbc14.jar (which is what I need, as I'm developing for 1.4.2) and NONE mention that the older oracle.jdbc.driver.OracleDriver class-package is deprecated.

    THANKS!!!

    Scott

  11. #11
    Thilahar is offline Member
    Join Date
    May 2011
    Posts
    4
    Rep Power
    0

    Default Re: ClassNotFoundException: oracle.jdbc.driver.OracleDriver

    For me showing this error when connected with my application - "java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver".
    Opened the Project properties page - Select the libraries column and Add JAR/Folder button to add the files from the "reference/jdbc Driver/oracle and the ...jar files" . now run the application and working correctly.
    So give the reference file path correctly.

Similar Threads

  1. Replies: 4
    Last Post: 03-31-2010, 01:08 PM
  2. Replies: 6
    Last Post: 02-19-2010, 02:57 PM
  3. Replies: 0
    Last Post: 03-21-2008, 02:13 PM
  4. Replies: 1
    Last Post: 03-14-2008, 03:51 PM
  5. Jdbc Driver For Oracle
    By Swamipsn in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 05:31 AM

Posting Permissions

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