Implement a ServletContextListener to get the DataSource and store it in
the ServletContext . See docs on the tomcat site and the servlet spec
for details.
--David
Divick Kishore wrote:
Hi,
I want to do one time initialization of some data at my back end
code when using tomcat as my container. To be precise I want to
initialize the DB connection to mysql db and later when connection is
requested from my DB layer I want to simply return the connection from
a connection pool. Thus loading of driver is one time thing. But I
don't know how to invoke some code which is done only once?
I understand that modifying server.xml and web.xml and putting the
driver jar in appropriate place the tomcat loads the driver
automatically and then using code like this one can get connection:
///The following code needs to be executed only once
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");
DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/javatest");
but this code needs to be invoked from somewhere so that I have
reference to DataSource but how to invoke it is not known and that is
what my confusion is. Please help.
Thanks,
Divick
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]