Solved MySQL: Illegal operation on empty result set.

Discussion in 'Spigot Plugin Development' started by Ginger_14, Jul 12, 2018.

Thread Status:
Not open for further replies.
  1. Hello! I have a problem...
    Here's what I have in the server console:
    [12:22:20] [Server thread/WARN]: java.sql.SQLException: Illegal operation on empty result set.
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5656)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5576)
    [12:22:20] [Server thread/WARN]: at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5616)
    [12:22:20] [Server thread/WARN]: at ru.oxygem.newwave.battles.mysql.Data.existsPlayer(Data.java:18)
    [12:22:20] [Server thread/WARN]: at ru.oxygem.newwave.battles.EventListener.onJoin(EventListener.java:28)
    [12:22:20] [Server thread/WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [12:22:20] [Server thread/WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    [12:22:20] [Server thread/WARN]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [12:22:20] [Server thread/WARN]: at java.lang.reflect.Method.invoke(Unknown Source)
    [12:22:20] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
    [12:22:20] [Server thread/WARN]: at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    [12:22:20] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
    [12:22:20] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:298)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:157)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java:148)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:814)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
    [12:22:20] [Server thread/WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
    [12:22:20] [Server thread/WARN]: at java.lang.Thread.run(Unknown Source)

    Code:
    public static String existsPlayer(String name) {
    try {
    PreparedStatement statement = SQLManager.getConnection().prepareStatement("SELECT * FROM users WHERE NAME=?");
    statement.setString(1, name.toLowerCase());
    ResultSet results = statement.executeQuery();
    if(results.next())
    //results.getString("name");
    if(results.getString("name") == null) {
    return "null";
    }
    return results.getString("name");
    } catch (SQLException e) {
    e.printStackTrace();
    return null;
    }
    }
    public static void createPlayer(String name) {
    try {
    PreparedStatement insert = SQLManager.getConnection().prepareStatement("INSERT INTO `users` (`name`, `level`, `points`, `kills`, `deaths`, `armor`, `weapons`, `bow`, `eat`) VALUES (?, 0, 0, 0, 0, 'default', 'default', 'no', 'no');");
    insert.setString(1, name);
    insert.executeUpdate();
    System.out.println("[Battles] Player successful registered!");
    } catch (SQLException e) {
    System.out.println("[Battles] ERROR! Player not registered! Check error message:");
    e.printStackTrace();
    }
    }
     
Thread Status:
Not open for further replies.