Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Posted on 2006-04-19
31
Medium Priority
?
358 Views
Last Modified: 2007-12-19
Hi,
I am trying to write a simple Java app using JDeveloper to connect to an Oracle database. Following is the simple code I use:

        Driver driver;
        String driverUsed = "oracle.jdbc.driver.OracleDriver";

        try {
            driver = (Driver)Class.forName(driverUsed).newInstance();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }

and this is what I get as output:
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
Loading ... oracle.jdbc.driver.OracleDriver
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:164)
      at win.MainFrame.buttonClose_actionPerformed(MainFrame.java:107)
      at win.MainFrame.mav$buttonClose_actionPerformed(MainFrame.java)
      at win.MainFrame$1.actionPerformed(MainFrame.java:68)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
      at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:231)
      at java.awt.Component.processMouseEvent(Component.java:5488)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
      at java.awt.Component.processEvent(Component.java:5253)
      at java.awt.Container.processEvent(Container.java:1966)
      at java.awt.Component.dispatchEventImpl(Component.java:3955)
      at java.awt.Container.dispatchEventImpl(Container.java:2024)
      at java.awt.Component.dispatchEvent(Component.java:3803)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
      at java.awt.Container.dispatchEventImpl(Container.java:2010)
      at java.awt.Window.dispatchEventImpl(Window.java:1774)
      at java.awt.Component.dispatchEvent(Component.java:3803)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:158)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Can somebody please help?

Note that I am using the JRE 1.4.2_04. I have a CLASSPATH=CLASSPATH=C:\J2EE\jdbc\lib defined. In this directory I have the ojdbc14.jar file which is the one that came with JDeveloper and the one Oracle says to be used with JRE 1.4 and 1.5.

I also tried putting the ojdbc14.jar file in my C:\Program Files\Java\j2re1.4.2\lib\ext directory but to no avail.

Any ideas anyone?
0
Comment
Question by:Cosine_Consultants
  • 13
  • 10
  • 6
  • +1
31 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16485901
Is ojdbc14.jar in your application classpath?`

Moreover, the CLASSPATH should be

CLASSPATH=%CLASSPATH%;C:\J2EE\jdbc\lib
0
 

Author Comment

by:Cosine_Consultants
ID: 16485925
What do you refer to when you say application classpath?
0
 
LVL 11

Expert Comment

by:fargo
ID: 16485955
where do u keep the libraries (3rd party etc.) required for your java app? Is it in location C:\J2EE\jdbc\lib?? If yes, that's the application classpath.

Moreover follow the way given in the link
http://javaalmanac.com/egs/java.sql/ConnectOracle.html

I believe, u need not to create a new instance for the driver..why?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Expert Comment

by:Mayank S
ID: 16486074
Here is a brush up on what class-path is:

http://www.mindprod.com/jgloss/classpath.html
0
 

Author Comment

by:Cosine_Consultants
ID: 16486258
fargo, I copied and pasted the way to connect as given in the provided link (needless to say I changed the parameters to some correct values). Still get the same error.

The funny thing is that I created a database connection using JDeveloper's wizard using the same parameters and it connected without any problems.
0
 
LVL 6

Expert Comment

by:avinthm
ID: 16486280
try adding classes11.jar and classes12.jar in your classpath
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486297
Perhaps JDeveloper's wizard automatically added those JARs to its class-path, that's why you did not face problems with it.
0
 

Author Comment

by:Cosine_Consultants
ID: 16486434
I tried adding classes12.zip in my classpath and nothing happened.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486493
Can you tell us the location of the classes12.zip file and how you added it to the class-path? Also open it in Winzip and check if it actually contains the OracleDriver class (otherwise its a corrupt file).
0
 
LVL 11

Expert Comment

by:fargo
ID: 16486511
can you crosscheck the classpath set in the environment.
echo %CLASSPATH%

paste the classpath here
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486528
If you have a 'cmd' command window open and if you change the class-path after that through My Computer -> Properties -> Advanced -> Environment variables, it will not recognize the changes in the class-path. You'll need to open another 'cmd' window.
0
 
LVL 6

Expert Comment

by:avinthm
ID: 16486543
> I tried adding classes12.zip
adding classes12.zip wont work.
you will have to add classes12.jar file
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486571
No, it would work if its a zip file too (that's how I use it).
0
 
LVL 11

Expert Comment

by:fargo
ID: 16486593
>> No, it would work if its a zip file too (that's how I use it).
i don't think so Mayank, it should work only with classes12.jar (jar file). Not with zip file.
0
 

Author Comment

by:Cosine_Consultants
ID: 16486614
My classpath is:
classpath=%CLASSPATH%;C:\J2EE\jdbc\lib\ojdbc14.jar;C:\J2EE\jdbc\lib\classes12.zip

both my ojdbc14.jar and classes12.zip exist in those directories defined in the classpath.
0
 
LVL 11

Expert Comment

by:fargo
ID: 16486633
Sorry mayank, i take my comments for zip file back

"Class files may be standalone, combined in zip files or combined in jar files. Java looks for class files in any directories mentioned in the CLASSPATH, but only searches jar and zip files if they are explicitly mentioned. A typical CLASSPATH statement might look like this: "
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486638
>> classpath=%CLASSPATH%;

That looks wierd, the %CLASSPATH% should not be there.
0
 

Author Comment

by:Cosine_Consultants
ID: 16486667
>>Can you tell us the location of the classes12.zip file and how you added it to the class-path? Also open it in Winzip and check if it actually contains the OracleDriver >>class (otherwise its a corrupt file).

I opened and checked it and indeed it contains the OracleDriver class.

This is really getting to the point of frustration. I'm starting to really dislike Java.
0
 

Author Comment

by:Cosine_Consultants
ID: 16486685
>> >> classpath=%CLASSPATH%;

>>That looks wierd, the %CLASSPATH% should not be there.

That doesn't make a difference. That simply states that the previous value CLASSPATH should be retained. It does not affect anything.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486933
>> Can you tell us the location of the classes12.zip file and how you added it to the class-path?

Did you add them to the class-path using SET CLASSPATH=.... ? Try adding them from My Computer -> Properties -> Advanced -> Environment variables and then check (open a new command window after that).

>> I'm starting to really dislike Java.

Be patient :)
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16486944
>> That doesn't make a difference. That simply states that the previous value CLASSPATH should be retained.

Yes but it does not show the full value of class-path. Anyway what I meant was can you tell what the class-path is from the My Computer -> Properties
0
 
LVL 11

Expert Comment

by:fargo
ID: 16486990
Moreover, classpath should be in capitals like CLASSPATH
in cmd window, if you do echo %CLASSPATH%, this should give all in classpath (without %CLASSPATH%)..it should give complete paths.









0
 

Author Comment

by:Cosine_Consultants
ID: 16487208
I solved my problem. The problem lied in JDeveloper and not in Java per se. When I run a java program in JDeveloper apparently, it assigned a CLASSPATH of its own - overiding the one I declared in my OS. I had to look around and set my application properties accordingly in order for it to work. And the funny thing is that it now works through JDeveloper without me having any CLASSPATH defined as a system variable. Go figure.

Anyway, thank you all for your help. Keep this in mind when using JDeveloper.

0
 
LVL 30

Accepted Solution

by:
Mayank S earned 375 total points
ID: 16487314
>> When I run a java program in JDeveloper apparently, it assigned a CLASSPATH of its own - overiding the one I declared in my OS

Yes, that is why we asked you to set up the classpath in the OS through My Computer -> Properties or through the command prompt, and that is why I told you:

>>  "JDeveloper's wizard automatically added those JARs to its class-path, that's why you did not face problems with it."

Lay stress on the "it's" word over there (means JDeveloper's class-path). Most IDEs generally use their own class-path, be it Eclipse, Netbeans, not just JDeveloper.

>> funny thing is that it now works through JDeveloper without me having any CLASSPATH defined as a system variable

Eclipse normally maintains the class-path in a .classpath file for every project from where it picks it up. I'm quite sure JDeveloper maintains it in something similar.
0
 

Author Comment

by:Cosine_Consultants
ID: 16487545
I did set up the classpath through the command prompt and then later through the My Computer-> Properties e.t.c.

But apparently it did not work.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16488252
You were trying to make it run from the command prompt, right?
0
 

Author Comment

by:Cosine_Consultants
ID: 16488344
No. Since I was using JDeveloper I was trying to run it through there.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16488378
Oh well, for some reason I thought you did development using JDeveloper and were trying to run from the command prompt. Since you said "I created a database connection using JDeveloper's wizard using the same parameters and it connected without any problems.", I thought you were able to connect using JDeveloper. Wrong track all the way, sorry, there was no need for setting the classpath in the OS from the command prompt or from My Computer -> Properties.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16488411
Nevertheless when you deploy this on a production machine which will not have JDeveloper, you will have to set up the system classpath as explained :)
0
 

Author Comment

by:Cosine_Consultants
ID: 16488422
Sorry for the mis-communication. I just didn't see the reason to develop in one environment and execute in another since it was a simple click of a button (of course as it turned out it wasn't a simple click of a button :-). But now it is.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16682443
>> I just didn't see the reason to develop in one environment and execute in another

It depends on the organization. They might use Windows systems for development whereas the client might want to run it on a Solaris server. Plus on the deployment machine, you will typically not have the development environment, IDE, etc - you will only have the runtime for running the application because you don't have to do development on that system. BTW, why the B grade?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question