wood burning stoves 2.0*
The moose likes Struts and the fly likes Connection creation @ server startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Connection creation @ server startup" Watch "Connection creation @ server startup" New topic
Author

Connection creation @ server startup

Kousik Majumder
Ranch Hand

Joined: Sep 30, 2007
Posts: 229
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: 2902
    
    1

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: 229
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
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

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: 2902
    
    1

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection creation @ server startup
 
Similar Threads
Start-up and shutdown class
starting the application
How to set virtual arguments in servlet
JCA and Message Driven Beans
Object Instantiation During Compliation and Deployment