SQL problems

Discussion in 'Plugin Development' started by Double0negative, Jun 5, 2012.

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

    Double0negative

    Hi.

    So, I seem to be having some sql problems in my plugin. Most of the time it works fine but sometimes it fail. I think that the connection might be timing out or something but im not sure how to fix it. here is the error that i receive

    http://pastie.org/4031769


    Help is appreciated as this is with my SurvivalGames plugin
     
  2. Code:
    if(conn == null || conn.isClosed())
        //Reconnect
     
    conn.prepareStatement(<blabla>);
    I do the above and haven't got any issues yet.
    conn is an instance of the connection (using the java MysqlConnector included in craftbukkit)
     
  3. Offline

    cdncampbell

    I would use the isValid(int) method as you can not use the isClosed() to correctly determine if a connection is active or not; according to the javadoc.

    Code:
    conn.isValid(0);
    With that said, if you catch any exceptions, you can force a reconnect.
     
    kumpelblase2 likes this.
  4. Thanks for clearing that up ;)
     
  5. Offline

    Double0negative

    Thanks, I'll implement this into the next update
     
  6. Offline

    wirher

    I use something like "keep connection alive thread". Simple "Select 1;" query every minute.
     
Thread Status:
Not open for further replies.

Share This Page