• Post Reply Bookmark Topic Watch Topic
  • New Topic

oracle.jdbc.driver.OracleDriver in my servlet, works fine with a java application

 
James Byars
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

my code is very similar for my java app and servlet (only difference being the obvious ones).

when I run the code as an application, I get a result from the database.

when I run the code from my servlet, I get oracle.jdbc.driver.OracleDriver

why is this?

(I am using Tomcat, Solaris 10)

thanks
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I suppose you meant to say you are getting exception mentioning that the Oracle driver not found.
Put the Oracle JAR file in the {tomcat.home}\lib directory and this error would go away.
 
James Byars
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
amit punekar wrote:Hi,
I suppose you meant to say you are getting exception mentioning that the Oracle driver not found.
Put the Oracle JAR file in the {tomcat.home}\lib directory and this error would go away.


well, if I have the ojdbc.jar in my classpath, why would it need to be in $CATALINA_HOME/lib?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying it's in /WEB-INF/lib?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, if I have the ojdbc.jar in my classpath

If you are talking about the system classpath, that's ignored at run-time.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JVM is unable to load the driver since it cannot find the required JAR. Putting it in WEB-INF/lib should help. A solution that is more crude would be to put it in the class path of the container.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:A solution that is more crude would be to put it in the class path of the container.

Crude? Hardly! Putting it in the container's lib folder allows it to be shared with multiple web apps. In fact, it's required if it's going to participate in container-managed connection pooling!
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Deepak Bala wrote:A solution that is more crude would be to put it in the class path of the container.

Crude? Hardly! Putting it in the container's lib folder allows it to be shared with multiple web apps. In fact, it's required if it's going to participate in container-managed connection pooling!


True if you want the container to manage the pooling. Bad if for some reason you do not want to share the jars (not necessarily the oracle jar in question) across all web apps. It depends on the user's perspective
 
James Byars
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, many thanks, I thought Tomcat would also add the normal classpath to its classpath. Now that I moved my ojdbc.jar to common/lib, it works.

So just in case someone else comes across this problem and googles, please be aware that Tomcat will ignore the system classpath

tomcat classpath ojdbc oracle.jdbc.driver.OracleDriver, servlet
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

So just in case someone else comes across this problem and googles, please be aware that Tomcat will ignore the system classpath


This should not be issue here. My thoughts are below.

This is related to the Class loader hierarchies. Because Child Class loader can see parent's classes but not opposite. Due to this even if you put Oracle JAR in WEB-INF\lib , its not available for tomcat while starting up to prepare the connection pool , as the JAR in WEB-INF\lib will be loaded by Web Application Class loader. That is the reason you have to put the JAR in {Tomcat.home}\lib folder so that it is loaded by Bootstrap class loader that boots up the Tomcat.

Reference:
Classes loaded by a class loader higher in the hierarchy cannot refer to classes available lower in the hierarchy.

Referred from - Check this

The above URL refers to the Sun Application server but this is the RULE for classloaders. I remember that I read it earlier for Weblogic server as well.

Regards,
Amit
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepak Bala wrote:True if you want the container to manage the pooling. Bad if for some reason you do not want to share the jars (not necessarily the oracle jar in question) across all web apps. It depends on the user's perspective

That doesn't make it "crude" or "bad". That's like saying putting something in the session is "crude" or "bad" because sometimes it may not need to be shared.

Obviously, use the configuration that makes sense, but don't call one "crude" or "bad" because it may not always be applicable.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Deepak Bala wrote:True if you want the container to manage the pooling. Bad if for some reason you do not want to share the jars (not necessarily the oracle jar in question) across all web apps. It depends on the user's perspective

That doesn't make it "crude" or "bad". That's like saying putting something in the session is "crude" or "bad" because sometimes it may not need to be shared.

Obviously, use the configuration that makes sense, but don't call one "crude" or "bad" because it may not always be applicable.


Yep ! It may not always be applicable.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!