 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Richard Hurt Guest
|
Posted: Mon Jan 05, 2004 7:25 pm Post subject: Preload JDBC Drivers in Tomcat |
|
|
Hey all,
I am trying to preload the DB2 JDBC driver in Tomcat. I am running
delivered code (I don't have source code ) that uses JDBC. The
problem is that whenever Tomcat restarts, I have to manually load the
DB2 driver. I wrote a stupid little JSP that calls
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
and after it runs everything works great - until we need to restart
Tomcat. I have tried just about everything I know of besides getting
the vendor to change their code to get this driver to preload in
either Tomcat 3.x & 4.x.
Here's what I have done so far:
o Added export CATALINA_OPTS="-Djdbc.drivers=COM.ibm.db2.jdbc.net.DB2Driver"
to the startup.sh script to force it to load.
o Added the following to my web.xml (both global & application):
<init-param>
<param-name>load-class</param-name>
<param-value>
COM.ibm.db2.jdbc.net.DB2Driver
</param-value>
</init-param>
o Moved db2java.zip around to different locations (shared/lib,
shared/classes, WEB-INF/lib, etc...)
I am still getting a "java.sql.SQLException: No suitable driver" error
whenever I try to use my application without "priming" the driver. I
am at my wits end. I would really love to get this working so I don't
have to run a little script everytime Tomcat does. Any hints?
Thanx!
Richard
|
|
| Back to top |
|
 |
David Rabinowitz Guest
|
Posted: Tue Jan 06, 2004 9:22 am Post subject: Re: Preload JDBC Drivers in Tomcat |
|
|
Add a ServletContextListener that does the Class.forName(...).
A wiser choice will be to have tomcat manage a DB2 DataSource for you,
see
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
David
Richard Hurt wrote:
| Quote: | Hey all,
I am trying to preload the DB2 JDBC driver in Tomcat. I am running
delivered code (I don't have source code ) that uses JDBC. The
problem is that whenever Tomcat restarts, I have to manually load the
DB2 driver. I wrote a stupid little JSP that calls
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
and after it runs everything works great - until we need to restart
Tomcat. I have tried just about everything I know of besides getting
the vendor to change their code to get this driver to preload in
either Tomcat 3.x & 4.x.
Here's what I have done so far:
o Added export CATALINA_OPTS="-Djdbc.drivers=COM.ibm.db2.jdbc.net.DB2Driver"
to the startup.sh script to force it to load.
o Added the following to my web.xml (both global & application):
init-param
param-name>load-class
param-value
COM.ibm.db2.jdbc.net.DB2Driver
/param-value
/init-param
o Moved db2java.zip around to different locations (shared/lib,
shared/classes, WEB-INF/lib, etc...)
I am still getting a "java.sql.SQLException: No suitable driver" error
whenever I try to use my application without "priming" the driver. I
am at my wits end. I would really love to get this working so I don't
have to run a little script everytime Tomcat does. Any hints?
Thanx!
Richard
|
|
|
| Back to top |
|
 |
Oscar Kind Guest
|
Posted: Tue Jan 06, 2004 8:34 pm Post subject: Re: Preload JDBC Drivers in Tomcat |
|
|
In comp.lang.java.help Richard Hurt <rhurt (AT) thepoint (DOT) net> wrote:
| Quote: | I am trying to preload the DB2 JDBC driver in Tomcat.
|
<snip: description of failed tries.>
Since you don't have the source code, you can't change the current code
base. Also, I'd advise against adding anything to it even though it's
certainly possible (and quite easy if you know what you're doing). The
reason is that if you get a new version, you'd have to do the same things
over again. Only a machine won't forget something. You will.
A better way of solving your problem, is by adding a very small
application to Tomcat at an unlikely context root (e.g. /sjfgdsjgfjdf).
This application consists of 2 files:
- A servlet that does nothing (or displays a page to that effect).
It must be a servlet however, because you want to implement its init()
method: the init() method loads the database driver.
- web.xml
This file defines a servlet that is loaded on startup (check the servlet
specs for a parameter called "load-on-startup"). This servlet is
implemented by the file above.
The end result is that the code to load the database driver (the init()
method of the servlet) is called whenever Tomcat starts.
Oscar
--
No trees were harmed in creating this message.
However, a large number of electrons were terribly inconvenienced.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|