Results 1 to 8 of 8
  1. #1
    major is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default Keep database connection alive

    I'm developing a windows desktop (standalone) application which runs as an endless loop.
    Once the application started, a database connection is created (java.sql.Connection) and from now on used to read data from the database.

    Connection is created like this:
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    Connection con = DriverManager.getConnection(connectionUrl);


    Does the connection will be kept alive forever?
    If NOT, what to change in my program?
    Last edited by major; 06-26-2011 at 01:44 PM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Depends on what scope you are opening the connection in and how long you leave it idle.

  3. #3
    major is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default

    By the way: My application is the only one to use this connection and perform step by step actions (sql queries). No use of threads.

    I would like to know what to do in both cases:
    1.connection needs to stay always opened
    2.connection is left idle for 15 minutes.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    1. Uhm, save the connection in a static context and open it only once, maybe (Edit: and a shutdown hook to close it properly, as well)?
    2. Well, what are the "session/connection timeout" settings for the DB in question?

  5. #5
    major is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Default

    2. no session/connection timeout (should I define this?).
    My program perform IO operations and web service calls also. so this operations may take additional time and meanwhile the connection is idle

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,474
    Rep Power
    21

    Default

    Since you'll have to handle the situation of a disconnect you may as well consider dealing with that from the start.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Quote Originally Posted by major View Post
    2. no session/connection timeout (should I define this?).
    The MySQL default is 8 hours.

  8. #8
    major is offline Member
    Join Date
    Jun 2011
    Posts
    12
    Rep Power
    0

    Thumbs up

    To summarize this issue: I don't need the added complexity of using connection pooling. If for some reason a failure happen, then just create a new one

Similar Threads

  1. connection to database
    By manojkumarsahu in forum New To Java
    Replies: 1
    Last Post: 08-06-2010, 09:26 PM
  2. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 0
    Last Post: 11-27-2009, 05:33 AM
  3. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 03:01 AM
  4. Keep my TCP connection alive
    By eggmanpete in forum Advanced Java
    Replies: 4
    Last Post: 03-02-2009, 07:11 AM
  5. Database Connection
    By vipinkumarsolanki in forum Advanced Java
    Replies: 2
    Last Post: 11-26-2007, 07:36 AM

Posting Permissions

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