Cosine_Consultants
asked on
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.Oracle Driver";
try {
driver = (Driver)Class.forName(driv erUsed).ne wInstance( );
}
catch (Exception ex) {
ex.printStackTrace();
}
and this is what I get as output:
java.lang.ClassNotFoundExc eption: oracle.jdbc.driver.OracleD river
Loading ... oracle.jdbc.driver.OracleD river
at java.net.URLClassLoader$1. run(URLCla ssLoader.j ava:200)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(UR LClassLoad er.java:18 8)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:306)
at sun.misc.Launcher$AppClass Loader.loa dClass(Lau ncher.java :268)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:251)
at java.lang.ClassLoader.load ClassInter nal(ClassL oader.java :319)
at java.lang.Class.forName0(N ative Method)
at java.lang.Class.forName(Cl ass.java:1 64)
at win.MainFrame.buttonClose_ actionPerf ormed(Main Frame.java :107)
at win.MainFrame.mav$buttonCl ose_action Performed( MainFrame. java)
at win.MainFrame$1.actionPerf ormed(Main Frame.java :68)
at javax.swing.AbstractButton .fireActio nPerformed (AbstractB utton.java :1849)
at javax.swing.AbstractButton $Handler.a ctionPerfo rmed(Abstr actButton. java:2169)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Defau ltButtonMo del.java:4 20)
at javax.swing.DefaultButtonM odel.setPr essed(Defa ultButtonM odel.java: 258)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (BasicButt onListener .java:234)
at java.awt.AWTEventMulticast er.mouseRe leased(AWT EventMulti caster.jav a:231)
at java.awt.Component.process MouseEvent (Component .java:5488 )
at javax.swing.JComponent.pro cessMouseE vent(JComp onent.java :3126)
at java.awt.Component.process Event(Comp onent.java :5253)
at java.awt.Container.process Event(Cont ainer.java :1966)
at java.awt.Component.dispatc hEventImpl (Component .java:3955 )
at java.awt.Container.dispatc hEventImpl (Container .java:2024 )
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Contai ner.java:4 212)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Contain er.java:38 92)
at java.awt.LightweightDispat cher.dispa tchEvent(C ontainer.j ava:3822)
at java.awt.Container.dispatc hEventImpl (Container .java:2010 )
at java.awt.Window.dispatchEv entImpl(Wi ndow.java: 1774)
at java.awt.Component.dispatc hEvent(Com ponent.jav a:3803)
at java.awt.EventQueue.dispat chEvent(Ev entQueue.j ava:463)
at java.awt.EventDispatchThre ad.pumpOne EventForHi erarchy(Ev entDispatc hThread.ja va:242)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Even tDispatchT hread.java :163)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 58)
at java.awt.EventDispatchThre ad.pumpEve nts(EventD ispatchThr ead.java:1 49)
at java.awt.EventDispatchThre ad.run(Eve ntDispatch Thread.jav a:110)
Can somebody please help?
Note that I am using the JRE 1.4.2_04. I have a CLASSPATH=CLASSPATH=C:\J2E E\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\e xt directory but to no avail.
Any ideas anyone?
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.Oracle
try {
driver = (Driver)Class.forName(driv
}
catch (Exception ex) {
ex.printStackTrace();
}
and this is what I get as output:
java.lang.ClassNotFoundExc
Loading ... oracle.jdbc.driver.OracleD
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
at java.lang.Class.forName0(N
at java.lang.Class.forName(Cl
at win.MainFrame.buttonClose_
at win.MainFrame.mav$buttonCl
at win.MainFrame$1.actionPerf
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.AWTEventMulticast
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
Can somebody please help?
Note that I am using the JRE 1.4.2_04. I have a CLASSPATH=CLASSPATH=C:\J2E
I also tried putting the ojdbc14.jar file in my C:\Program Files\Java\j2re1.4.2\lib\e
Any ideas anyone?
ASKER
What do you refer to when you say application classpath?
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?
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?
ASKER
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.
The funny thing is that I created a database connection using JDeveloper's wizard using the same parameters and it connected without any problems.
try adding classes11.jar and classes12.jar in your classpath
Perhaps JDeveloper's wizard automatically added those JARs to its class-path, that's why you did not face problems with it.
ASKER
I tried adding classes12.zip in my classpath and nothing happened.
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).
can you crosscheck the classpath set in the environment.
echo %CLASSPATH%
paste the classpath here
echo %CLASSPATH%
paste the classpath here
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.
> I tried adding classes12.zip
adding classes12.zip wont work.
you will have to add classes12.jar file
adding classes12.zip wont work.
you will have to add classes12.jar file
No, it would work if its a zip file too (that's how I use it).
>> 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.
i don't think so Mayank, it should work only with classes12.jar (jar file). Not with zip file.
ASKER
My classpath is:
classpath=%CLASSPATH%;C:\J 2EE\jdbc\l ib\ojdbc14 .jar;C:\J2 EE\jdbc\li b\classes1 2.zip
both my ojdbc14.jar and classes12.zip exist in those directories defined in the classpath.
classpath=%CLASSPATH%;C:\J
both my ojdbc14.jar and classes12.zip exist in those directories defined in the classpath.
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: "
"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: "
>> classpath=%CLASSPATH%;
That looks wierd, the %CLASSPATH% should not be there.
That looks wierd, the %CLASSPATH% should not be there.
ASKER
>>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.
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.
ASKER
>> >> 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.
>>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.
>> 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 :)
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 :)
>> 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
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
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.
in cmd window, if you do echo %CLASSPATH%, this should give all in classpath (without %CLASSPATH%)..it should give complete paths.
ASKER
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.
Anyway, thank you all for your help. Keep this in mind when using JDeveloper.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
But apparently it did not work.
You were trying to make it run from the command prompt, right?
ASKER
No. Since I was using JDeveloper I was trying to run it through there.
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.
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 :)
ASKER
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.
>> 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?
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?
Moreover, the CLASSPATH should be
CLASSPATH=%CLASSPATH%;C:\J