Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Tomcat 5.5.9, correct directory for DB driver?

Reply
Thread Tools

Tomcat 5.5.9, correct directory for DB driver?

 
 
elektrophyte
Guest
Posts: n/a
 
      09-25-2005
I'm using Tomcat 5.5.9 on Windows 2000. I get the error below when I
try to visit a page of my app that accesses the DB.

I've tried putting the DB driver "mysql-connector-java-3.1.8-bin.jar"
in these locations:

[TOMCAT_HOME]\common\lib
[TOMCAT_HOME]\common\endorsed
[TOMCAT_HOME]\webapps\agenda\WEB-INF\lib
C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext

These are all directories that have been recommended in books, in
Tomcat docs, or in newsgroups as the place to put jar files like DB
drivers. I don't know if one, some, none, or all is the right
directory. In fact it seems to be one of the great mysteries of the
universe. Maybe there's an old guy sitting on top of a mountain in
Tibet who knows what the correct directory for database drivers is.

I notice that the Tomcat distribution also includes the
suggestively-named directory "shared\lib". I've never heard anyone say
that's the right one, but if you have a database driver that is clearly
a "library" and you want it to be available, or "shared" by all your
applications, then "shared\lib" might be a reasonable place to put it.
However I tried it and got the same error.

If anyone has any insight into the issues mentioned I'd be grateful to
hear it.

Thanks,

E

The error -->
================================================== ==============
Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'

[...]

Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.jav a:243)

 
Reply With Quote
 
 
 
 
James Yong
Guest
Posts: n/a
 
      09-25-2005

"elektrophyte" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> I'm using Tomcat 5.5.9 on Windows 2000. I get the error below when I
> try to visit a page of my app that accesses the DB.
>
> I've tried putting the DB driver "mysql-connector-java-3.1.8-bin.jar"
> in these locations:
>
> [TOMCAT_HOME]\common\lib
> [TOMCAT_HOME]\common\endorsed
> [TOMCAT_HOME]\webapps\agenda\WEB-INF\lib
> C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext
>
> These are all directories that have been recommended in books, in
> Tomcat docs, or in newsgroups as the place to put jar files like DB
> drivers. I don't know if one, some, none, or all is the right
> directory. In fact it seems to be one of the great mysteries of the
> universe. Maybe there's an old guy sitting on top of a mountain in
> Tibet who knows what the correct directory for database drivers is.
>
> I notice that the Tomcat distribution also includes the
> suggestively-named directory "shared\lib". I've never heard anyone say
> that's the right one, but if you have a database driver that is clearly
> a "library" and you want it to be available, or "shared" by all your
> applications, then "shared\lib" might be a reasonable place to put it.
> However I tried it and got the same error.
>
> If anyone has any insight into the issues mentioned I'd be grateful to
> hear it.
>
> Thanks,
>
> E
>
> The error -->
> ================================================== ==============
> Cannot create JDBC driver of class '' for connect URL 'null'
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
> driver of class '' for connect URL 'null'
>
> [...]
>
> Caused by: java.sql.SQLException: No suitable driver
> at java.sql.DriverManager.getDriver(DriverManager.jav a:243)
>


Hi,

I suggest that you removed all copies of the driver and put only one in
common/lib.

I think the probable cause is the incorrect setting of the datasource in
server.xml of tomcat.

Regards,
james yong


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-25-2005
On 24 Sep 2005 19:23:41 -0700, "elektrophyte" <(E-Mail Removed)>
wrote or quoted :

>Tibet who knows what the correct directory for database drivers is.


an where on the classpath path should be ok. See
http://mindprod.com/jgloss/properties.html to find out the
java.classpath system property.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      09-25-2005
http://www.velocityreviews.com/forums/(E-Mail Removed)lid said:
>On 24 Sep 2005 19:23:41 -0700, "elektrophyte" <(E-Mail Removed)>
>wrote or quoted :
>
>>Tibet who knows what the correct directory for database drivers is.

>
>an where on the classpath path should be ok. See
>http://mindprod.com/jgloss/properties.html to find out the
>java.classpath system property.


No, won't be reliable with Tomcat (could've worked somewhat with 3.x
series, perhaps 4.0, but not with 4.1 and onwards). Tomcat uses
rather extensively private classloaders, which do not honor system
classpath, but instead have classpaths explicitly configured. With
4.1.x the classpath configuration was very limited; with 5.x the
classpath configuration is vastly improved.

Initially this might not look like a good idea, but at least for
me this has proven to be extremely valuable tool to isolate the
Tomcat server environment from pretty much all influences of
command-line environment variables. I've seen cases of hard-to-trace
breakage when someone has "just made some small change to an
environment variable", and as a result the next Tomcat restart
(perhaps weeks later) fails -- or at least the application
misbehaves.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      09-25-2005
"elektrophyte" <(E-Mail Removed)> said:
>I've tried putting the DB driver "mysql-connector-java-3.1.8-bin.jar"
>in these locations:
>
>[TOMCAT_HOME]\common\lib
>[TOMCAT_HOME]\common\endorsed
>[TOMCAT_HOME]\webapps\agenda\WEB-INF\lib
>C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext
>
>These are all directories that have been recommended in books, in
>Tomcat docs, or in newsgroups as the place to put jar files like DB
>drivers. I don't know if one, some, none, or all is the right
>directory. In fact it seems to be one of the great mysteries of the
>universe. Maybe there's an old guy sitting on top of a mountain in
>Tibet who knows what the correct directory for database drivers is.


Read, and re-read, the Tomcat classloading documentation. Digesting
it will take some time - just accept that.

Then, if you create the database connections as you should (i.e.
by using the jdbc connection pooling support provided by Tomcat,
instead of creating the connections within your application),
place the library in common/lib. And make sure you don't have
compies of the library elsewhere -- there could be one hiding in
the Tomcat work directory for your webapp.

>The error -->
>================================================= ===============
>Cannot create JDBC driver of class '' for connect URL 'null'
>org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
>driver of class '' for connect URL 'null'
>
>[...]
>
>Caused by: java.sql.SQLException: No suitable driver
> at java.sql.DriverManager.getDriver(DriverManager.jav a:243)


.... but this somewhat looks like there isn't even an attempt to
load the mysql driver -- which could be caused by a bug in your
configuration.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
elektrophyte
Guest
Posts: n/a
 
      09-25-2005
James Yong wrote:
> >
> > The error -->
> > ================================================== ==============
> > Cannot create JDBC driver of class '' for connect URL 'null'
> > org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
> > driver of class '' for connect URL 'null'
> >
> > [...]
> >
> > Caused by: java.sql.SQLException: No suitable driver
> > at java.sql.DriverManager.getDriver(DriverManager.jav a:243)
> >

>
> Hi,
>
> I suggest that you removed all copies of the driver and put only one in
> common/lib.
>
> I think the probable cause is the incorrect setting of the datasource in
> server.xml of tomcat.
>
> Regards,
> james yong


Thanks for the reply. I did have an error in server.xml. I put the
driver in common/lib and it works. Onward!

E

 
Reply With Quote
 
elektrophyte
Guest
Posts: n/a
 
      09-26-2005
> Then, if you create the database connections as you should (i.e.
> by using the jdbc connection pooling support provided by Tomcat,
> instead of creating the connections within your application),
> place the library in common/lib. And make sure you don't have
> compies of the library elsewhere -- there could be one hiding in
> the Tomcat work directory for your webapp.


I edited server.xml to create a DB connection pool and make it a JNDI
resource. That now seems to work. I've also read various things about
where that connection pool resource configuration goes. Some say it
should be in conf\Catalina\localhost\WEBAPP_NAME.xml. I've also read
you should deploy it with the webapp in META-INF\context.xml.

However, I've found that, as you said, putting the configuration in
server.xml within the <Host name="localhost" ... > ... </Host> element
works. I put it right before the closing </Host> tag.

This is my server.xml context config that works on Tomcat 5.5.9 on
Windows 2000:

<Context path="/agenda" docBase="agenda">
<Resource name="jdbc/localagendads" auth="Container"
type="javax.sql.DataSource" maxActive="100" maxIdle="30"
maxWait="10000" username="USERNAME" password="PASSWORD"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/agenda" />
</Context>

Also have to add this to web.xml:

<resource-ref>
<description>Local DB connection</description>
<res-ref-name>jdbc/localagendads</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

 
Reply With Quote
 
Juha Laiho
Guest
Posts: n/a
 
      09-26-2005
"elektrophyte" <(E-Mail Removed)> said:
>> Then, if you create the database connections as you should (i.e.
>> by using the jdbc connection pooling support provided by Tomcat,
>> instead of creating the connections within your application),
>> place the library in common/lib. And make sure you don't have
>> compies of the library elsewhere -- there could be one hiding in
>> the Tomcat work directory for your webapp.

>
>I edited server.xml to create a DB connection pool and make it a JNDI
>resource. That now seems to work. I've also read various things about
>where that connection pool resource configuration goes. Some say it
>should be in conf\Catalina\localhost\WEBAPP_NAME.xml. I've also read
>you should deploy it with the webapp in META-INF\context.xml.
>
>However, I've found that, as you said, putting the configuration in
>server.xml within the <Host name="localhost" ... > ... </Host> element
>works. I put it right before the closing </Host> tag.


These different ways provide various levels of isolation - and
various levels of centralization.

For example, consider a situation where you deploy a final test
and production instances of an application to a single machine.
Both set the same database requirement in WEB-INF/web.xml, but
still you want to point these instances into separate databases.

This is where you need the "middle level" of webapp_name.xml
(or META-INF/context.xml within the webapp package). Even
with this model, you could encode the database information
directly in these "middle level" files, but I rather keep the
database configuration in single point (in server.xml), and
use these "middle level" files to map names as required by the
application to the names I use in the JNDI registry.

This way, I can deploy the exact same .war file to either
test or production instance, and the deployment environment
will handle the differences in databases and other external
requirements - and I still get to keep the actual JNDI
configuration in a single place in server.xml.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
simulation result is correct but synthesis result is not correct J.Ram VHDL 7 12-03-2008 01:26 PM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Correct White Balance Doesn't Mean Correct Color?? jim evans Digital Photography 28 12-27-2005 05:10 AM
correct or not correct? Dan HTML 7 10-02-2003 10:16 PM
To correct my program. please, check to find errors and correct me. joon Java 1 07-08-2003 06:13 AM



Advertisments