Results 1 to 2 of 2
  1. #1
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    271
    Rep Power
    11

    Default Database Connection Lifetime

    Just a quick question. Say I have a service that accesses a database. Is it better to open/close a connection per request to the servlet, as needed? Or is it better to open a connection once, and keep it open for the duration of the application, thus sharing the connections among the requests?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Database Connection Lifetime

    Option 3: use a connection pool. You want to keep connections open (which the pool will take care of for you) but you do NOT want to share connections among different threads.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Set up lifetime in session
    By severuspedreirus in forum Java Servlet
    Replies: 0
    Last Post: 06-23-2013, 05:24 PM
  2. connection to database
    By manojkumarsahu in forum New To Java
    Replies: 1
    Last Post: 08-06-2010, 09:26 PM
  3. connection to database
    By buston01 in forum JDBC
    Replies: 4
    Last Post: 02-21-2010, 01:32 AM
  4. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 0
    Last Post: 11-27-2009, 04:33 AM
  5. Database Connection
    By CompleteBeginner in forum New To Java
    Replies: 2
    Last Post: 05-24-2008, 02:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •