This discussion is archived
8 Replies Latest reply: Jan 23, 2013 9:13 AM by Tolls RSS

ClassNotFound Exception

Raja_236 Newbie
Currently Being Moderated
Hi,

while executing below program am getting classNotexception, please suggest what mistake i have done here

import java.sql.*;
public class JDBC_Ex {
public static void main(String[] args) {

System.out.println("TestJDBCDriverInstallation_Oracle begin");
try {
String className = "oracle.jdbc.driver.OracleDriver";
Class driverObject = Class.forName(className);
System.out.println("driverObject=" + driverObject);
System.out.println("your installation of JDBC Driver OK.");
} catch (Exception e) {
// your installation of JDBC Driver Failed
System.out.println("Failed: JDBC Driver Error: " + e.getMessage());
}

System.out.println("TestJDBCDriverInstallation_Oracle end.");
}


}
  • 1. Re: ClassNotFound Exception
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!

    Whenever you post provide the full versions of: your database, Java, jdbc jar file and name.
    >
    while executing below program am getting classNotexception, please suggest what mistake i have done here
    >
    No one can help you if you don't provide the information needed to understand the EXACT problem you are having.

    Which of the thousands of classes is not being found?

    That exception means that Java cannot find the class on the classpath.

    And the use of 'Class.forName' hasn't bee needed for several years now.
  • 2. Re: ClassNotFound Exception
    Raja_236 Newbie
    Currently Being Moderated
    Thanks,

    i have set the classpath for ojdbc14.jar file & this is executing while running the application see below

    Class.forName("oracle.jdbc.OracleDriver");
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "box","box");

    and am trying to execute this one as posted program getting ClassNotfoundException


    O/P

    java -cp C:\Users\Raja\Desktop\ojdbc14.jar JDBC_ex
    ain" java.lang.NoClassDefFoundError: JDBC_ex
    lassNotFoundException: JDBC_ex
    LClassLoader$1.run(Unknown Source)
    ty.AccessController.doPrivileged(Native Method)
    LClassLoader.findClass(Unknown Source)
    lassLoader.loadClass(Unknown Source)
    uncher$AppClassLoader.loadClass(Unknown Source)
    lassLoader.loadClass(Unknown Source)
    lassLoader.loadClassInternal(Unknown Source)
    n class: JDBC_ex. Program will exit.

    Edited by: 983428 on Jan 22, 2013 9:16 AM
  • 3. Re: ClassNotFound Exception
    Tolls Journeyer
    Currently Being Moderated
    983428 wrote:
         } catch (Exception e) {
    // your installation of JDBC Driver Failed
    System.out.println("Failed: JDBC Driver Error: " + e.getMessage());
    }
    Use e.printStackTrace().
    You are losing an awful lot of information by simply relying on getMessage.

    In any case, my crystal ball is telling me you haven't got the jdbc driver on your classpath.
  • 4. Re: ClassNotFound Exception
    Raja_236 Newbie
    Currently Being Moderated
    i have set the class path before executing program

    classpath = .;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip;C:\Users\Raja\
    Desktop\ojdbc14.jar
  • 5. Re: ClassNotFound Exception
    rp0428 Guru
    Currently Being Moderated
    The text you posted is garbage. You need to post EXACTLY the entire text and messages that you are getting.

    And you need to provide the information asked for:
    >
    Whenever you post provide the full versions of: your database, Java, jdbc jar file and name.
    >
    When you post code you need to add \
     on the line before and after the code to preserve formatting.
    
    And the ojdbc14.jar file is ancient. Why aren't you using the current version?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  • 6. Re: ClassNotFound Exception
    Tolls Journeyer
    Currently Being Moderated
    983428 wrote:
    java -cp C:\Users\Raja\Desktop\ojdbc14.jar JDBC_ex
    ain" java.lang.NoClassDefFoundError: *JDBC_ex*
    lassNotFoundException: JDBC_ex
    LClassLoader$1.run(Unknown Source)
    ty.AccessController.doPrivileged(Native Method)
    LClassLoader.findClass(Unknown Source)
    lassLoader.loadClass(Unknown Source)
    uncher$AppClassLoader.loadClass(Unknown Source)
    lassLoader.loadClass(Unknown Source)
    lassLoader.loadClassInternal(Unknown Source)
    n class: JDBC_ex. Program will exit.

    Edited by: 983428 on Jan 22, 2013 9:16 AM
    Though this is gibberish it does (amazingly) have the problem in it.
    Java is case sensitive and, from your first post, your class is called Java_Ex, not Java_ex.
  • 7. Re: ClassNotFound Exception
    rp0428 Guru
    Currently Being Moderated
    >
    your class is called Java_Ex, not Java_ex.
    >
    Perhaps you meant 'JDBC_Ex'? ;)
  • 8. Re: ClassNotFound Exception
    Tolls Journeyer
    Currently Being Moderated
    rp0428 wrote:
    >
    your class is called Java_Ex, not Java_ex.
    >
    Perhaps you meant 'JDBC_Ex'? ;)
    Picky picky picky...:)

    (damn damn damn)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points