JDBC auto disconnect after 8 hours

Discussion in 'Plugin Development' started by zipron, Aug 30, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    zipron

    JDBC will auto disconnect if nothing happened for 8 hours. Is it enough to add ?autoreconnect=true to the driver URL, or do I need to do a lot more to prevent this from happening?

    zip

    actually, why does no single guide sais the right solution? just open your connection each time to execute a query and close it after doing it? such an easy solution and the best way to do it =P​

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    Giant

    It is enough to add the autoreconnect to the URL, however, that is not exactly clean... It also means that the query that it occurred on, will be lost.
    I would suggest checking if the connection is still valid before attempting to execute the query. As when it's no longer valid, you can then simply make a new connection! :)

    Here is an example of such a check.
     
  3. Offline

    zipron

    hmm, I did that too, but it's much more cleaner and safer to close and re-open the con each time. That's the way I did it in php and now also here, don't think I'll be in trouble anymore =)
     
  4. Offline

    Giant

    The only downside of closing and reopening after each execution would be that whilst in php, that was pretty much session wide, each refresh would be a new session. In Java however the connection gets shared over all things. And besides of that, seeing how most minecraft servers with MySQL run on an external server, if you were to close/reopen the connection everytime, that will slow your plugin down quite a bit, especially if the database you connect to is slow... :(
     
  5. Offline

    zipron

    oh I have my own server, so it doesn't really matter. Also added caching to my plugins today so won't have to open connections a lot, I think for me, it's the best solution =)

    (I btw only use my plugins on my own server =), so doesn't matter if other have slow DB's, their bad =D)
     
  6. Offline

    Giant

    Fair enough then! :D
     
Thread Status:
Not open for further replies.

Share This Page