• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to initialize connection pool withou restarting Tomcat

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

I'm using Tomcat 5.5, Spring framework and HSQLDB database. My goal is to install application on new computer to ($CATALINA_HOME/webapps) and after running it I would like the install page to show. On thi page, user would be able to set path to the database. This information would go into properties file as well as username and password for the database. After leaving the install page I would like the application to work normally withou restarting Tomcat.

Does anybody have an idea how to do it. I need to initialize connection pool without restarting Tomcat? Any help would be very appritiated.

Thanks, Tom.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if you can.
Tomcat's integral connection pool is apparently DBCP registered with JNDI. That would be fairly easy to replicate in your own code and you'd have complete control over it.
 
Tomas Sara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Joe,

I tried to do it using DBCP page and I made my own implementation of DataSource. After this I tried to use it in Tomcat but I was not successful at this.

As I wrote at the begining we are using Spring so I put into the context.xml file the following


Then I copied jar file with my class to "$CATALINA_HOME/commons/lib" directory so Tomcat should be now able to use it. After redeploying the project I got java.sql.SQLException: No suitable driver exception.

Does anybody have any idea how to solve my problem??

Thanks in advance,
Tom.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tomas Sara:
and I made my own implementation of DataSource.


Why would you do such a thing if DBCP has one? I don't know how to integrate it with Spring, but using DBCP should be this simple:

DBCP Package Summary

Originally posted by Tomas Sara:
Then I copied jar file with my class to "$CATALINA_HOME/commons/lib" directory so Tomcat should be now able to use it.



Since you are creating a connection pool in your application for your application's own use, Tomcat doesn't need to know about it. And if you don't want to restart Tomcat, it shouldn't know about your pool.
Furthermore, if you are getting an "java.sql.SQLException: No suitable driver" exception, the problem is that the JVM can't find your database driver. That is probably the root of your problems. Where do you have the HSQLDB jar file?
 
Tomas Sara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick answer.

When I was writing about the new implementation I did the same you suggested.

After making the class you should make jar file of it and copy it to Tomcat. Otherwise Tomcat can't use your class to make the pool.

I have HSQLDB on the local harddisk in the directory I have full access to. I'm using connection string like this jdbc:hsqldb:hsql://localhost/dbName.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tomas Sara:

After making the class you should make jar file of it and copy it to Tomcat. Otherwise Tomcat can't use your class to make the pool.


What I'm saying is that you don't want Tomcat to manage your pool at all. If you do that, you'll have to restart it after configuring it.
If you create the pool yourself in your application, you have full reign over it.

Originally posted by Tomas Sara:

I have HSQLDB on the local harddisk in the directory I have full access to.


Where is the driver JAR file? It has to be somewhere your application classloader can access it, usually WEB-INF/lib
 
Tomas Sara
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What I'm saying is that you don't want Tomcat to manage your pool at all. If you do that, you'll have to restart it after configuring it.
If you create the pool yourself in your application, you have full reign over it.



Thanks a lot for this. I will try to do it. It looks like you understand it a lot. Could you push me to the right direction how to do it?

Where is the driver JAR file? It has to be somewhere your application classloader can access it, usually WEB-INF/lib.



I have the driver exactly where you wrote - WEB-INF/lib.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tomas Sara:

Could you push me to the right direction how to do it?



I gave you the code on the 18th. The only other detail left is registering the pool instance with JNDI or putting it in a utility class so you can access it anywhere in your program.

Originally posted by Tomas Sara:

I have the driver exactly where you wrote - WEB-INF/lib.



Do you register the HSQLDB driver in your application code as detailed in the documentation (Example 1.1)?
 
reply
    Bookmark Topic Watch Topic
  • New Topic