• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about shared DB connection

 
arnold yan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read from Manning JSP book that I can create a db connection object and set it as an attribute of the application object so this db connection can be shared by all JSPs and All users of this application.
My question is, what is going to happen when there is concurrent access to the db connection, say, multiple users queries/updates the database through this db connection at the same time? If this setup works, then what is the point to implement connection pooling?
Thanks for your words of wisdom.
Arnold
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously concurrent use by multiple requests would be a disaster. You would have to provide for synchronizing on the connection to prevent that, and you would also have to provide for regenerating the connection if it got closed by the database end, etc etc.
You might as well use a connection pool.
Bill
 
Vijayanandh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage of connection pooling is that u have more number of database connections ready for use. Hence it can support many requests at a given instance, which implies scalability.
Its not the same with the shared DBConnection
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general, all these older mechanisms are made nearly obsolete by JSTL's <sql:*> tags. These tags generally use DataSource objects that are managed behind the scenes, thus making the JSP pages simpler and the access both correct and efficient (assuming the DataSource is correct and efficient). Of course, this all assumes you want to access databases from your JSP pages directly.
 
Claude Nicholson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr Bayern,

I am used to the old way of using jsp to interact with databases and the problems associated with connections, etc.

I have been experimenting with beans to handle all business logic, generally how does jstl work and is it's benefit only to database access.

Need a jump start on the topic.
Thanks
 
Claude Nicholson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont worry dude
Found some information on earlier postings. To be honest I have heard of taglibaries but concentrated on beans to do the work.
Does your book cover all i'd need to now to effectively use it. Cause it seems based on some of the postings that the functionality of jstl depends on the server used.
I asked for a jump start before now I need a road.

Thanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!