| Author |
Connection creation @ server startup
|
Kousik Majumder
Ranch Hand
Joined: Sep 30, 2007
Posts: 219
|
|
Hi All,
I need to create a set of connection at server startup. I am using struts with datasource.
So I need an action class to use getDataSource(req,key) function .
Please tell me an elegant way how can I do that ?
|
Thanks in Advance,
Kousik
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
|
Do you want database connection, then use Tomcat/DBCP/JNDI
|
[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
|
 |
Kousik Majumder
Ranch Hand
Joined: Sep 30, 2007
Posts: 219
|
|
yes, I am using DBCP.
Actually I want to know that at server start up how can I make database connection. Like we can declare a servlet at load-on-startup and do whatever we want to.
But here I have to use an Action class to use getDataSource(req,key) function. Is there any way to declare a Action class so that it can load some DB connection at server startup.
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
If you are using connection pool, then what is the need to load connections at startup?? The pool will automatically contain connection for you to use. Anyways why do you want to do this with only an action not a ServletContextListener or load-on-startup servlet??
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Sagar Rohankar
Ranch Hand
Joined: Feb 19, 2008
Posts: 2896
|
|
Kousik Majumder wrote:But here I have to use an Action class to use getDataSource(req,key) function. Is there any way to declare a Action class so that it can load some DB connection at server startup.
Once you define the data source in context.xml, then it automatically get connection pool at web app deployment. What you need is model as DAO(Data Access Object) getting the connection object thru JNDI(InitialContext) [This is may be considered as summary of the link I had given]
|
 |
 |
|
|
subject: Connection creation @ server startup
|
|
|