• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection creation @ server startup

 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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 ?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want database connection, then use Tomcat/DBCP/JNDI
 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic