Solved MySQL Help

Discussion in 'Plugin Development' started by Wizehh, Jan 27, 2014.

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

    Wizehh

    Edit: After I do /reload or first start the server, connections to the database work for about 60 seconds; then, this happens (if I restart it will work - for 60 seconds):
    PHP:
    [13:47:27 WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionExceptionNo operations allowed after
        connection closed
    .Connection was implicitly closed by the driver.
        [
    13:47:27 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        [
    13:47:27 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        [
    13:47:27 WARN]:        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        [
    13:47:27 WARN]:        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.Util.getInstance(Util.java:382)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1213)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1200)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4203)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4169)
        [
    13:47:27 WARN]:        at (Tribe.java:198)
        [
    13:47:27 WARN]:        at (Tribe.java:290)
        [
    13:47:27 WARN]:        at (Spawn.java:69)
        [
    13:47:27 WARN]:        at (CommandManager.java:80)
        [
    13:47:27 WARN]:        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        [
    13:47:27 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:196)
        [
    13:47:27 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:542)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:932)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
        [
    13:47:27 WARN]: Caused bycom.mysql.jdbc.exceptions.jdbc4.CommunicationsExceptionCommunications link failure
     
        The last packet successfully received from the server was 78
    ,371 milliseconds ago.  The last packet sent successful
        ly to the server was 0 milliseconds ago
    .
        [
    13:47:27 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        [
    13:47:27 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        [
    13:47:27 WARN]:        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        [
    13:47:27 WARN]:        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3082)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2968)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3516)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
        [
    13:47:27 WARN]:        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2273)
        [
    13:47:27 WARN]:        at ********(Tribe.java:205)
        [
    13:47:27 WARN]:        at c***********(TribeManager.java:41)
        [
    13:47:27 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        [
    13:47:27 WARN]:        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        [
    13:47:27 WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        [
    13:47:27 WARN]:        at java.lang.reflect.Method.invoke(Unknown Source)
        [
    13:47:27 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        [
    13:47:27 WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        [
    13:47:27 WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481)
        [
    13:47:27 WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42)
        [
    13:47:27 WARN]:        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149)
        [
    13:47:27 WARN]:        ... 6 more
        
    [13:47:27 WARN]: Caused byjava.io.EOFExceptionCan not read response from serverExpected to read 4 bytesread
        0 bytes before connection was unexpectedly lost
    .
     
  2. Offline

    sebasju1234

    Can you post your code?
     
  3. Offline

    Wizehh

    sebasju1234 Why? Also, the connection only times out after about 60 seconds of the plugin being enabled.
     
  4. Offline

    sebasju1234

    Otherwise we can't help you because we can't see what you are doing..
     
  5. Offline

    Wizehh

    Code:java
    1. public synchronized static void openConnection() {
    2. try {
    3. connection = DriverManager.getConnection("jdbc:mysql://******:3306/*****", "******", "*****");
    4. Console.info("MySQL connection opened.");
    5. } catch (Exception e) {
    6. Console.severe("SQL Connection could not be opened!");
    7. e.printStackTrace();
    8. }
    9. }
    10.  
    11. public synchronized static void closeConnection() {
    12. try {
    13. connection.close();
    14. Console.info("SQL Connection has been closed!");
    15. } catch (Exception e) {
    16. Console.severe("Connection could not be closed!");
    17. e.printStackTrace();
    18. }
    19. }
    20.  
    21. public synchronized static boolean playerDataContainsPlayer(Player p) {
    22.  
    23. try {
    24. if (Main.connection == null) {
    25. Main.openConnection();
    26. }
    27. PreparedStatement ps = connection.prepareStatement("SELECT * FROM `player_data` WHERE player=?;");
    28. ps.setString(1, p.getName());
    29. ResultSet rs = ps.executeQuery();
    30. boolean containsPlayer = rs.next();
    31.  
    32. ps.close();
    33. rs.close();
    34. return containsPlayer;
    35. } catch (Exception e) {
    36. e.printStackTrace();
    37. return false;
    38. }
    39. }
     
  6. Offline

    sebasju1234

    You are trying to do something after you've closed your connection.
     
  7. Offline

    Wizehh

    sebasju1234 But I'm not closing the connection, only the result sets and queries.
     
  8. Offline

    sebasju1234

  9. Offline

    Wizehh

  10. Offline

    calebbfmv

    Wizehh
    I believe its the use of synchronized.
     
  11. Offline

    Wizehh

  12. Offline

    sebasju1234

    Why should I? It's a great tutorial that could help you. Oh and by the way.. you shouldn't send LetMeGoogleThatForYou links to people that want help or tell them to watch episode 1 of a Bukkit plugin development serie. But oh well..
     
  13. Offline

    Wizehh

    calebbfmv That did not work :/

    sebasju1234 That post is not going to help..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  14. Offline

    1Rogue

    What's wrong with the post he linked? Looks perfectly clear to me.
     
  15. Offline

    Wizehh

    1Rogue Please read my stack trace.
     
  16. Offline

    1Rogue


    Yup, and he linked a post that can show some tips on proper SQL instantiation.
     
  17. Offline

    Wizehh

    1Rogue I've read it.

    pls

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  18. Offline

    calebbfmv

    Wizehh
    Stop bumping, read it, you will find your error. Do debugging. And for future reference, if at anytime you need help on the forums, post code, because if the code was so amazing, you wouldn't need us.
     
  19. Offline

    Wizehh

    calebbfmv Please don't jump to assumptions; I have been debugging for about 3 days.

    Hmm. Maybe I need to stop the connection from timing out? I could setup a task to reopen the connection every 1200 ticks, but that lags the server..
    Edit: Does anyone know anything about connection pooling? I think that might solve the issue.

    bump

    Still unsolved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
    VinexAx789 likes this.
  20. Offline

    DailyLove

    try moving the synchornized keyword from your playerDataContainsPlayer method, but keep them on your openConnection and closeConnection methods.
     
  21. Offline

    Wizehh

    Maybe AutoReconnect=true will solve the problem?
     
  22. Offline

    calebbfmv

    Wizehh
    Maybe listening to what we said instead of being too prideful to realize that we already fixed it.
     
  23. Offline

    Wizehh

  24. Offline

    calebbfmv

    Wizehh
    A: Reading post
    B: Understanding post
    C: Reading stacktrace
    D: Change the connection settings to open and close WHEN NEEDED
    E: Less bumping
     
  25. Offline

    Wizehh

    calebbfmv
    A: Did
    B: Did..
    C: Did.. many times
    D: I can't do that.
    E: Okay :3
     
  26. Offline

    Maurdekye

    Fucking christ, all you unrelenting bastards. Can't you see his problem isn't with his understanding of how to implement MySQL with java? If he said it originally works for at least 60 seconds, then Java isn't having any problems connecting to MySQL, and he's not doing anything wrong in his code. The problem is on the server end; he's getting kicked out 60 seconds after he opens the connection. Likely there's a MySQL verification error going on here. If it's running locally, (which it's not, because you wouldn't hide your ip address otherwise), then I could help you, but otherwise you might have to provide information about the account your server uses to connect to MySQL.
     
    gomeow likes this.
  27. Offline

    Wizehh

    Maurdekye Thank you. I added autoReconnect?=true, but to no avail.
    I really don't know what the issue is :/
    Edit: I think this might be important:
    PHP:
    The last packet successfully received from the server was 118,492 milliseconds ago.  The last packet sent successfully to the server was 5 milliseconds ago.
    So, it can send just fine, but it can't read..


    PHP:
    [18:52:03 WARN]: com.mysql.jdbc.exceptions.jdbc4.CommunicationsExceptionCommunications link failure
     
    The last packet successfully received from the server was 118
    ,492 milliseconds ago.  The last packet sent successfu
    lly to the server was 5 milliseconds ago
    .
    [
    18:52:03 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [
    18:52:03 WARN]:        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    [
    18:52:03 WARN]:        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    [
    18:52:03 WARN]:        at java.lang.reflect.Constructor.newInstance(Unknown Source)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3082)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2968)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3516)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2273)
    [
    18:52:03 WARN]:        at com.tribes.tribes.Tribe.isInTribe(Tribe.java:197)
    [
    18:52:03 WARN]:        at com.tribes.tcommands.Info.onCommand(Info.java:20)
    [
    18:52:03 WARN]:        at com.tribes.tribes.CommandManager.onCommand(CommandManager.java:80)
    [
    18:52:03 WARN]:        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [
    18:52:03 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:196)
    [
    18:52:03 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:542)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:932)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457)
    [
    18:52:03 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
    [
    18:52:03 WARN]: Caused byjava.io.EOFExceptionCan not read response from serverExpected to read 4 bytesread
    0 bytes before connection was unexpectedly lost
    .
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2529)
    [
    18:52:03 WARN]:        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2979)
    [
    18:52:03 WARN]:        ... 24 more
     
  28. Offline

    Maurdekye

    Wizehh It it hosted on your local computer?
     
  29. Offline

    Wizehh

    Maurdekye No. I'm currently using my GoDaddy (-.-) website to host the database; however, I will be moving the database to a dedi' once I'm done with the testing.
    Edit: If you were referring to the Minecraft server, then yes, I am (for now) hosting it locally.
     
  30. Offline

    Maurdekye

    Wizehh Try hosting the MySQL server locally, and see if you get the same problem.
     
Thread Status:
Not open for further replies.

Share This Page