• 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

Connection creation @ server startup

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want database connection, then use Tomcat/DBCP/JNDI
 
Kousik Majumder
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic