• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Tag Lib

 
adnan22
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, if we create a custom tag that is used to make connections to databases...then how can we make a conection alive so that it can be be reused between different requests?
Is there any other alternative to this problem
Adnan Memon
SCJP2
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The alternative that I would suggest is that you dont create connections to databases from tags... but that is because I come from an enterprise enviornment where the app that I am working on has to service more that 100,000 people
But if you did want to do what you say, I would use some db connection pooling software, and then just grab a connection from the pool when you want one.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connection pooling is indeed the answer. Candidate #1 is probably your application server; any full-blown J2EE server allows you to set up DataSources that are bound in JNDI. So your tag would look up the DataSource from a known JNDI location (or one pulled from a tag attribute) and request a Connection from it.
Candidate #2 is a connection pool such as the GenericDataSource that comes with Struts.
- Peter
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good and easy to use Connection Pool class can be found at http://www.javaexchange.com Called the DbConnectionBroker.
adnan22,
JavaRanch has a Naming Policy Please read and change your display name to follow it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic