1
votes

my Java application crashes while I build up a PreparedStatement for JDBC.

[10:34:13] java.net.SocketInputStream.socketRead0(Native Method)
[10:34:13] java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
[10:34:13] java.net.SocketInputStream.read(SocketInputStream.java:171)
[10:34:13] java.net.SocketInputStream.read(SocketInputStream.java:141)
[10:34:13] com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114)
[10:34:13] com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161)
[10:34:13] com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189)
[10:34:13] com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2526)
[10:34:13] com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2979)
[10:34:13] com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2968)
[10:34:13] com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3516)
[10:34:13] com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
[10:34:13] com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
[10:34:13] com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
[10:34:13] com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2111)
[10:34:13] com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2273)

Here is the code:

try {
        PreparedStatement ps = SQL_Falldamaged.con.prepareStatement("SELECT Count FROM Count WHERE Port = ?");
        ps.setInt(1, port);
        ResultSet rs = ps.executeQuery();
        while(rs.next()) {
            return rs.getInt("Count");
        }
    } catch (SQLException e) {}
    return -1;

Can anyone see what´s wrong here?

Thanks for the help

MS

EDIT:

[10:34:13] [Spigot Watchdog Thread/ERROR]:      *.*.getCount(SQL_Falldamaged_Count.java:25)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      *.*.kompass(Kompass.java:222)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      *.*.onJoin(Kompass.java:45)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      java.lang.reflect.Method.invoke(Method.java:498)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:107)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:623)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      java.util.concurrent.FutureTask.run(FutureTask.java:266)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
[10:34:13] [Spigot Watchdog Thread/ERROR]:      java.lang.Thread.run(Thread.java:745)

Here is how I setup the Connection: con = DriverManager.getConnection("jdbc:mysql://:3306/", "**", "*");

1
Offhand, count is a reserved word. But don't guess - print the error message from the exception you're catching instead of ignoring it, and share it with us. - Mureinik
That's not a crash. That's an exception. But you failed to provide its complete stack trace, so we don't have the type, message and location of the exception. - JB Nizet
Please post the full exception stacktrace. Your current one is missing at least the exception type and message, and maybe more. And as Mureinik says, you are currently swallowing exception. At minimum log them or print them using e.printStackTrace. - Mark Rotteveel
Ok, added a stacktrace, its the PreparedStatement Line. - M. Schröder
And you still failed to post the entire stack trace. The first line, containing the type and message of the exception, is the most important one. - JB Nizet

1 Answers

1
votes

ps.setQueryTimeout(1);

This solution worked