Results 1 to 5 of 5
  1. #1
    jkjmomadad is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Exception in thread "main" java.lang.ClassNotFoundException: jdbc.odbc.driver.Oracle

    I am using Netbeans 7.1.2. I have been having a terrible time trying to connect to a remote Oracle database. I was given the appropriate url from my professor, and told to install ojdbc.6 from Oracle which I did by adding it to the class path, but I'm still having no luck at all actually getting the data from the database. I can go in manually and connect. I am using the simple code below (from my text) to try to start troubleshooting the issue - see below. Any help that can be given would be super appreciated.

    Java Code:
    package javaapplication6;
    
    import java.sql.*;
    
    public class JavaApplication6 {
             
             public static void main(String[] args)
                     throws SQLException, ClassNotFoundException {
                 Class.forName("jdbc.odbc.driver.OracleDriver");
                 System.out.println("Driver loaded");
                 
                 Connection connection = DriverManager.getConnection
                         ("jdbc:oracle:thin:@XXXXX:port:xxxx","username","password");
                 System.out.println("Database connected");
                 
                 Statement statement = connection.createStatement();
                 
                 ResultSet resultSet = statement.executeQuery("SELECT * FROM POWER");
                 
                 while (resultSet.next())
                     System.out.println(resultSet.getString(2));
                 
                 connection.close();
                 
                         
             }
        
    }
    Exception info is below:

    run:
    Exception in thread "main" java.lang.ClassNotFoundException: jdbc.odbc.driver.OracleDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at javaapplication6.JavaApplication6.main(JavaApplica tion6.java:11)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)
    Last edited by jkjmomadad; 07-16-2012 at 07:47 PM.

  2. #2
    doWhile is online now Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Exception in thread "main" java.lang.ClassNotFoundException: jdbc.odbc.driver.Ora

    I did by adding it to the class path
    The exception says otherwise. How are you adding the database driver to the classpath?

  3. #3
    jkjmomadad is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Re: Exception in thread "main" java.lang.ClassNotFoundException: jdbc.odbc.driver.Ora

    Perhaps I've done it wrong; I right-clicked the project, selected properties, selected Libraries, selected Compile tab, Add Jar/Folder. I then browsed to the copy of ojdbc6.jar that was provided and added it; I see the odjdbc6 driver there which was given to us to install. I'm new to this so any insight you can give would be helpful.

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

    Default Re: Exception in thread "main" java.lang.ClassNotFoundException: jdbc.odbc.driver.Ora

    You don't need the jar file to compile.
    You need it at runtime.
    I haven't got Netbeans in front of me, but there should be somewhere to tell it that this jar file is a runtime dependency.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    jkjmomadad is offline Member
    Join Date
    Jul 2012
    Posts
    3
    Rep Power
    0

    Default Re: Exception in thread "main" java.lang.ClassNotFoundException: jdbc.odbc.driver.Ora

    Many thanks - it's working now.

Similar Threads

  1. Replies: 2
    Last Post: 06-20-2012, 12:18 AM
  2. Replies: 5
    Last Post: 12-21-2011, 06:44 PM
  3. Replies: 14
    Last Post: 04-08-2011, 06:01 PM
  4. Replies: 0
    Last Post: 02-11-2011, 03:21 PM
  5. Replies: 5
    Last Post: 06-22-2010, 03:51 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
  •