Results 1 to 8 of 8
  1. #1
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default question about connection efficiency in database

    Hi
    I am developing an application that sends data to the database (MySQL) of a website each 5 minutes (i.e. I am updating the record each 5 minutes).
    the sent data has this form
    "10101010001000100010101010109922342123456"
    my question is:
    should I keep the connection open and update the data each five minutes and never close the connection; or should I close the connection after each update and re-open it again (i.e. establishing the connection again after 5 minutes for the next update) and in general what is the difference between the two approaches regarding the java application and the response of the website, any ideas, reviews?

    Regards.
    Anderson.
    Last edited by mr_anderson; 07-28-2010 at 03:39 PM.

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    196
    Rep Power
    5

    Default

    I would open and close it. If you keep it open, it will degrade in time. Also, if you keep it open, for security matters, someone could access your db and mess with it with possible sql injection
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Sno View Post
    I would open and close it. If you keep it open, it will degrade in time. Also, if you keep it open, for security matters, someone could access your db and mess with it with possible sql injection
    I disagree; opening and closing a connection can be very resource demanding; I'd say keep it open. It is the responsibility of the database engine that a connection can not be stolen by a third party and it has nothing to do with SQL injection.

    kind regards,

    Jos
    Last edited by JosAH; 07-28-2010 at 07:45 PM.

  4. #4
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    Hi guys
    thank you for your replies, JosAH can you please clarify what do you mean by "resource demanding" do you mean the resources of the PC or the resources of the website?
    Regards.
    Anderson.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by mr_anderson View Post
    Hi guys
    thank you for your replies, JosAH can you please clarify what do you mean by "resource demanding" do you mean the resources of the PC or the resources of the website?
    Both; opening a connection takes quite a bit of resources on the side where your database engine runs and it can take resources on the client side as well. Allocating and releasing those resources over and over again is unnecessary, just do it once and keep the resouces for as long as possible and needed.

    kind regards,

    Jos

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

    Default

    Making db connections isn't so bad these days, to be honest. And they are only doing it every 5 minutes. And connections should be viewed as a scarce resource. However, if there's nothing else using the db (or not much else using it, in terms of numbers of connections) I'd just hold onto the connection...bearing in mind that you might lose it.

  7. #7
    mr_anderson is offline Member
    Join Date
    May 2010
    Location
    Florida
    Posts
    68
    Rep Power
    0

    Default

    I have thought with the issue of losing the connection in case of keeping it open although I can simply solve this issue in the try-catch block.
    By the way does the orums use the same technique?
    I mean when I enter my user-name and password and log in to the forum I can post as much as I want, any comments about this?
    Thank you guys for your replies.
    Anderson.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

Similar Threads

  1. An Efficiency Question
    By Revenna in forum Java 2D
    Replies: 0
    Last Post: 06-25-2010, 07:22 AM
  2. connection to database
    By buston01 in forum JDBC
    Replies: 4
    Last Post: 02-21-2010, 01:32 AM
  3. getting database connection
    By ravidasineni in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 02:01 AM
  4. database connection in jsf
    By Srikala in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 10-06-2008, 06:53 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
  •