1
votes

I'm using SQLite. When im trying to get an int, it doest work. I used this exaclty like this earlier in this program, but now it wonst work anymore. I Hopy, you can help me. PS: Sry 4 my bad english. I going to write some random thinks here, because i this Window says, that i have to write a few more words, because there's more code then text.

The getting method

    public static boolean getBold(UUID uuid) {
        try {
            PreparedStatement state = MySQL.c.prepareStatement("SELECT * From Chat where uuid=?");
            state.setString(1, uuid.toString());

            ResultSet rs = state.executeQuery();
            rs.next();

            int i = rs.getInt("bold");


            rs.close();
            state.close();

            if(i == 1){
                return true;
            }else {
                return false;
            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        return false;

    }

The Error:

[19:42:36] [Server thread/WARN]: java.sql.SQLException: ResultSet closed
[19:42:36] [Server thread/WARN]:    at org.sqlite.RS.checkOpen(RS.java:63)
[19:42:36] [Server thread/WARN]:    at org.sqlite.RS.findColumn(RS.java:108)
[19:42:36] [Server thread/WARN]:    at org.sqlite.RS.getInt(RS.java:293)
[19:42:36] [Server thread/WARN]:    at de.primeapi.chatsystem.mysql.ChatStats.getBold(ChatStats.java:57)
[19:42:36] [Server thread/WARN]:    at de.primeapi.chatsystem.commands.BoldCommand.onCommand(BoldCommand.java:22)
[19:42:36] [Server thread/WARN]:    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
[19:42:36] [Server thread/WARN]:    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
[19:42:36] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1162)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:997)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
[19:42:36] [Server thread/WARN]:    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[19:42:36] [Server thread/WARN]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
[19:42:36] [Server thread/WARN]:    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
[19:42:36] [Server thread/WARN]:    at java.lang.Thread.run(Thread.java:748)

My SQLClass:

    public static Connection c;

    public static void connect() {
        try {
            Class.forName("org.sqlite.JDBC");
            String url = "jdbc:sqlite:plugins/ChatSystem/database.sql";
            c = DriverManager.getConnection(url);
            System.out.println("[SQLite] Connected.");
        } catch (SQLException e) {
            System.out.println("[SQLite] Connection failed.");
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void disconnect() {
        if (c != null) {
            try {
                c.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public static void update(String qry) {
        try {
            Statement stmt = c.createStatement();
            stmt.executeUpdate(qry);
            stmt.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
            disconnect();
            connect();
        }
    }
1
I bet your query is empty, i.e. the SELECT returned nothing, i.e. rs.next() returned false, and you didn't check for that.Andreas
FYI: You should use try-with-resources.Andreas

1 Answers

0
votes

The error java.sql.SQLException: ResultSet closed appears when you reuse a SQL Statement or your Query is empty. You could start checking these two points.