Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Optimizing JDBC connection w/ JSP  RSS feed

 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
This is an extension of a previous post of mine. I'm new to JSP and I have an implementation question:
When connecting to a database, should I:
1.) use a bean with application scope so database access from different pages/sessions will not require a new Connection() - it will simply reuse the existing bean's Connection
2.) use a DataSource object to exploit connection pooling
I'm sure there a plenty of differences in these 2 implementations, and if anyone has any suggestions on which would be better, I'd appreciate it. Thanks,
WS
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a bean with application scope so database access from different pages/sessions will not require a new Connection() - it will simply reuse the existing bean's Connection

And if more than one page at a time wants to use the connection...???
This is why you need connection pooling. Remember that a web app is a multi-threaded animal.
That said, you could place a connection pool in app scope (bean-wrapped or otherwise) for easy access by all elements of the web app. But a single connection shared amongst all pages won't cut it.
hth,
bear
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the speedy reply, Bear. I'll go ahead and implement option 2 based on your advice!
WS
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!