You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by jcrowell <jc...@rics.bwh.harvard.edu> on 2004/06/05 01:07:46 UTC

non-servlet helper class to use the tomcat connection pool

I have a helper class which performs spell checking for all my web
applications.  Since this class never talks to the client it is not a
servlet.  Instead, it is just sits in $CATALINA_HOME/common/lib in a jar
file and waits for any servlet that needs a word spell checked to send it a
request.  Also, since I need only one spell checker (and only one dictionary
in RAM) this class is a singleton.
 
What I want to know is: can I use the tomcat global connection pooling
resource that I have set up (in the <GlobalNamingResources> element in
conf\server.xml) when this class needs to access the database?
 
In other words, how do I access a connection from the connection pool when I
am not dealing with a JSP or a servlet, and the singleton class is not
necessarily associated with any particular webapp?
 
Is this even possible?
 
I am running Windows XP pro, Tomcat 5.0.24.
 
Thanks much,
 
Jon
 
 

Re: non-servlet helper class to use the tomcat connection pool

Posted by QM <qm...@brandxdev.net>.
On Fri, Jun 04, 2004 at 07:07:46PM -0400, jcrowell wrote:
: In other words, how do I access a connection from the connection pool when I
: am not dealing with a JSP or a servlet, and the singleton class is not
: necessarily associated with any particular webapp?

If I understand your question: yes.
As long as a class is run within Tomcat, the pools (and other JNDI
resources) are available to it.

The examples in the docs for accessing a pool, those aren't limited to
servlets or other web-centric code.


You'd do yourself a favor, though, to abstract/centralize your DB access --
or, better yet, your general persistence logic -- into a separate helper
class.  That would make your code more flexible in the long run.

-QM

-- 

software  -- http://www.brandxdev.net
tech news -- http://www.RoarNetworX.com


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org