ClassNotFoundException: oracle.jdbc.driver.OracleDriver

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?
Cosine_ConsultantsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fargoCommented:
Is ojdbc14.jar in your application classpath?`

Moreover, the CLASSPATH should be

CLASSPATH=%CLASSPATH%;C:\J2EE\jdbc\lib
0
Cosine_ConsultantsAuthor Commented:
What do you refer to when you say application classpath?
0
fargoCommented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mayank SAssociate Director - Product EngineeringCommented:
Here is a brush up on what class-path is:

http://www.mindprod.com/jgloss/classpath.html
0
Cosine_ConsultantsAuthor Commented:
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
avinthmCommented:
try adding classes11.jar and classes12.jar in your classpath
0
Mayank SAssociate Director - Product EngineeringCommented:
Perhaps JDeveloper's wizard automatically added those JARs to its class-path, that's why you did not face problems with it.
0
Cosine_ConsultantsAuthor Commented:
I tried adding classes12.zip in my classpath and nothing happened.
0
Mayank SAssociate Director - Product EngineeringCommented:
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
fargoCommented:
can you crosscheck the classpath set in the environment.
echo %CLASSPATH%

paste the classpath here
0
Mayank SAssociate Director - Product EngineeringCommented:
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
avinthmCommented:
> I tried adding classes12.zip
adding classes12.zip wont work.
you will have to add classes12.jar file
0
Mayank SAssociate Director - Product EngineeringCommented:
No, it would work if its a zip file too (that's how I use it).
0
fargoCommented:
>> 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
Cosine_ConsultantsAuthor Commented:
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
fargoCommented:
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
Mayank SAssociate Director - Product EngineeringCommented:
>> classpath=%CLASSPATH%;

That looks wierd, the %CLASSPATH% should not be there.
0
Cosine_ConsultantsAuthor Commented:
>>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
Cosine_ConsultantsAuthor Commented:
>> >> 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
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
fargoCommented:
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
Cosine_ConsultantsAuthor Commented:
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
Mayank SAssociate Director - Product EngineeringCommented:
>> 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cosine_ConsultantsAuthor Commented:
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
Mayank SAssociate Director - Product EngineeringCommented:
You were trying to make it run from the command prompt, right?
0
Cosine_ConsultantsAuthor Commented:
No. Since I was using JDeveloper I was trying to run it through there.
0
Mayank SAssociate Director - Product EngineeringCommented:
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
Mayank SAssociate Director - Product EngineeringCommented:
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
Cosine_ConsultantsAuthor Commented:
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
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.