Solved Using MySQL Error (EOFException)

Discussion in 'Plugin Development' started by mazentheamazin, Mar 29, 2014.

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

    mazentheamazin

    Hello,

    Currently I have been making a point system for a plugin of mine and ran into an error (I'm using -_Husky_- 's Resource for using MySQL in Bukkit plugins). Here some information:
    Stacktrace:
    Code:
    [18:28:53 WARN]: Caused by: java.io.EOFException: Can not read response from ser
    ver. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly l
    ost.
    [18:28:53 WARN]:        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2529)
    [18:28:53 WARN]:        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.jav
    a:2979)
    [18:28:53 WARN]:        ... 36 more
    Whole class:
    Code:java
    1. import org.bukkit.Bukkit;
    2.  
    3. import java.sql.ResultSet;
    4. import java.sql.SQLException;
    5. import java.sql.Statement;
    6.  
    7. public class PointPlayer {
    8.  
    9. private Statement statement;
    10. private String playerName;
    11. private int balance = 0;
    12. private ResultSet res;
    13.  
    14. public PointPlayer(String player) {
    15. try{
    16. statement = instance.c.createStatement();
    17. playerName = player;
    18. res = statement.executeQuery("SELECT * FROM points WHERE PlayerName = '" + playerName + "';");
    19. while(res.next()) {
    20. if(res.getString("PlayerName") != null) {
    21. balance = res.getInt("points");
    22. if(balance == 0) {
    23. this.addPoints(50);
    24. }
    25. }else{
    26. statement.executeUpdate("INSERT INTO points ('PlayerName', 'points') VALUES ('" + playerName + "', '50');");
    27. }
    28. }
    29. }catch(SQLException e) {e.printStackTrace();}
    30. }
    31.  
    32. public void addPoints(int amount) {
    33. balance = balance + amount;
    34. updateValues();
    35. }
    36.  
    37. private void updateValues() {
    38. try{
    39. startConnection();
    40. Bukkit.broadcastMessage(playerName + "." + balance);
    41. statement = instance.c.createStatement();
    42. statement.executeUpdate("INSERT INTO points ('PlayerName', 'points') VALUES ('" +
    43. playerName + "', '" +
    44. balance + "');");
    45. }catch(SQLException e) {e.printStackTrace();}
    46. }
    47.  
    48. public void setPoints(int bal) {
    49. this.balance = bal;
    50. updateValues();
    51. }
    52.  
    53. public void removePoints(int amount) {
    54. if((balance - amount) == 0) {
    55. return;
    56. }
    57. balance = balance - amount;
    58. updateValues();
    59. }
    60.  
    61. public int getBalance() {
    62. return balance;
    63. }
    64.  
    65. public boolean hasAmount(int amount) {
    66. return balance >= amount;
    67. }
    68.  
    69. public void startConnection() {
    70. instance.mySQL.openConnection();
    71. instance.mySQL.getConnection();
    72. }
    73. }

    One of the stacktraces I saw pointed to this line:
    Code:java
    1. res = statement.executeQuery("SELECT * FROM points WHERE PlayerName = '" + playerName + "';");

    I am hosting the MySQL database from GoDaddy, and created the table manually through PHPMyAdmin.

    Any help is appreciated ;)
     
  2. Offline

    2MBKindiegames

    I'm sorry, is this topic solved or not?
     
  3. Offline

    TopTobster5

    By the looks of things, the server is not communicating with your plugin. Have you logged into the server on your main class? Try hoisting the server so me where else and see if the problem carry's on.
     
  4. Offline

    valon750

    mazentheamazin
    Did you happen to leave it for a while before calling this? I find that same issue when leaving he server for a while, then having a method called that attempts to access the server.

    Reloading seems to resolve the issue, so I feel safe putting it down to a timeout issue, despite me having it check the connection whenever running a method regarding mysql.
     
  5. Offline

    mazentheamazin

    valon750
    +1 for necrodooming a thread xD I've fixed this a long time ago, hence why this the thread tag 'Solved'
     
Thread Status:
Not open for further replies.

Share This Page