Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fundamental & Good Practice When to Connect to dB when to run statements

 
Robert Spero
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am drawing the framework for my first web application that uses data from an existing database. There will be absolutely no writing to the database just SELECT queries into arrays.

From a fundamental standpoint, there is a button on the form that will conect to the database and create an array and close the connection. Are there any advantages on making the connection in the context and queries in the session rather than opening and closing if there is no writing to the database?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. If you never close the connection, it wastes resources and could time out. Instead the best practice is to use a connection pool.
 
Robert Spero
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne - Thank You

 
Zachary Pry
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Robert,

Official JDBC Basics tutorial.

Section related to Pooled Connections

Pooled DataSource can be configured and received from Server, or your can use Pooled DataSource provided by some of the JDBC drivers.

If JDBC Driver doesn't provide Pooled DataSource - I am recommending to look at Apache Commons DBCP or C3P0.

Hope it helps.
 
Robert Spero
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow thanks Zachary
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic