[JDBC] Mysterious SQLException with ResultSet

Discussion in 'Plugin Development' started by TheA13X, Oct 21, 2013.

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

    TheA13X

    Hi there!
    I have some trouble with my Plugin.
    As I said in the title I'm using JDBC and then a wild Exception appears:
    Code:
    2013-10-21 21:56:59 [SEVERE] java.sql.SQLException: Operation not allowed after
    ResultSet closed
    2013-10-21 21:56:59 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQ
    LError.java:1073)
    2013-10-21 21:56:59 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
    2013-10-21 21:56:59 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQ
    LError.java:982)
    2013-10-21 21:56:59 [SEVERE]    at com.mysql.jdbc.SQLError.createSQLException(SQ
    LError.java:927)
    2013-10-21 21:56:59 [SEVERE]    at com.mysql.jdbc.ResultSetImpl.checkClosed(Resu
    ltSetImpl.java:794)
    2013-10-21 21:56:59 [SEVERE]    at com.mysql.jdbc.ResultSetImpl.next(ResultSetIm
    pl.java:7145)
    2013-10-21 21:56:59 [SEVERE]    at de.A13X.Commands.SZACCommand.subzonecheck(SZACCommand.java:2349)
    2013-10-21 21:56:59 [SEVERE]    at de.A13X.Commands.SZACCommand.onCommand(SZACCo
    mmand.java:485)
    2013-10-21 21:56:59 [SEVERE]    at org.bukkit.command.PluginCommand.execute(Plug
    inCommand.java:44)
    2013-10-21 21:56:59 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(
    SimpleCommandMap.java:192)
    2013-10-21 21:56:59 [SEVERE]    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.di
    spatchCommand(CraftServer.java:523)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.PlayerConnection
    .handleCommand(PlayerConnection.java:959)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.PlayerConnection
    .chat(PlayerConnection.java:877)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.PlayerConnection
    .a(PlayerConnection.java:834)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.Packet3Chat.hand
    le(SourceFile:49)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.NetworkManager.b
    (NetworkManager.java:296)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.PlayerConnection
    .e(PlayerConnection.java:116)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.ServerConnection
    .b(SourceFile:37)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedServerC
    onnection.b(SourceFile:30)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.
    t(MinecraftServer.java:592)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.DedicatedServer.
    t(DedicatedServer.java:227)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.
    s(MinecraftServer.java:488)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.MinecraftServer.
    run(MinecraftServer.java:421)
    2013-10-21 21:56:59 [SEVERE]    at net.minecraft.server.v1_6_R3.ThreadServerAppl
    ication.run(SourceFile:583)
    The thing is, that the Result set is NOT closed!
    Look at this:
    Code:java
    1. 2307 private boolean subzonecheck(Location[] locationArray, String string,Player player) throws SQLException{
    2. 2308 if(Szm.getConnection().isClosed()){
    3. 2309 Szm.openConnection();
    4. 2310 }
    5. 2311 double xzone1;
    6. 2312 double xzone2;
    7. 2313 double zzone1;
    8. 2314 double zzone2;
    9. 2315 double x1;
    10. 2316 double x2;
    11. 2317 double z1;
    12. 2318 double z2;
    13. 2319 if(locationArray[0].getX()>locationArray[1].getX()){
    14. 2320 x1=Math.ceil(locationArray[0].getX());
    15. 2321 }
    16. 2322 else{
    17. 2323 x1=Math.floor(locationArray[0].getX());
    18. 2324 }
    19. 2325
    20. 2326 if(locationArray[1].getX()>locationArray[0].getX()){
    21. 2327 x2=Math.ceil(locationArray[1].getX());
    22. 2328 }
    23. 2329 else{
    24. 2330 x2=Math.floor(locationArray[1].getX());
    25. 2331 }
    26. 2332
    27. 2333 if(locationArray[0].getZ()>locationArray[1].getZ()){
    28. 2334 z1=Math.ceil(locationArray[0].getZ());
    29. 2335 }
    30. 2336 else{
    31. 2337 z1=Math.floor(locationArray[0].getZ());
    32. 2338 }
    33. 2339
    34. 2340 if(locationArray[1].getZ()>locationArray[0].getZ()){
    35. 2341 z2=Math.ceil(locationArray[1].getZ());
    36. 2342 }
    37. 2343 else{
    38. 2344 z2=Math.floor(locationArray[1].getZ());
    39. 2345 }
    40. 2346 PreparedStatement sql = Szm.getConnection().prepareStatement("SELECT `name`,`owner`,`locx`,`locz`,`locx2`,`locz2 FROM `SZMzones_" + locationArray[0].getWorld().getName() + "` WHERE `owner`=?");
    41. 2347 sql.setString(1, string);
    42. 2348 ResultSet rs = sql.executeQuery();
    43. 2349 while(rs.next()){
    44. 2350 if(rs.getDouble(3)>rs.getDouble(5)){
    45. 2351 xzone1=Math.ceil(rs.getDouble(3));
    46. 2352 }
    47. 2353 else{
    48. 2354 xzone1=Math.floor(rs.getDouble(3));
    49. 2355 }
    50. 2356
    51. 2357 if(rs.getDouble(5)>rs.getDouble(3)){
    52. 2358 xzone2=Math.ceil(rs.getDouble(5));
    53. 2359 }
    54. 2360 else{
    55. 2361 xzone2=Math.floor(rs.getDouble(5));
    56. 2362 }
    57. 2363
    58. 2364 if(rs.getDouble(4)>rs.getDouble(6)){
    59. 2365 zzone1=Math.ceil(rs.getDouble(4));
    60. 2366 }
    61. 2367 else{
    62. 2368 zzone1=Math.floor(rs.getDouble(4));
    63. 2369 }
    64. 2370
    65. 2371 if(rs.getDouble(6)>rs.getDouble(4)){
    66. 2372 zzone2=Math.ceil(rs.getDouble(6));
    67. 2373 }
    68. 2374 else{
    69. 2375 zzone2=Math.floor(rs.getDouble(6));
    70. 2376 }
    71. 2377 if(Math.max(x1, x2) <= Math.max(xzone1, xzone2) && Math.max(z1, z2) <= Math.max(zzone1, zzone2) && Math.min(x1, x2) >= Math.min(xzone1, xzone2) && Math.min(z1, z2) > Math.min(zzone1, zzone2)){
    72. 2378 name=rs.getString(1);
    73. 2379 owner=rs.getString(2);
    74. 2380 sql.close();
    75. 2390 rs.close();
    76. 2391 }
    77. 2392 }


    Thanks to the Snippet-function of Eclipse I could find out, that the SQL-Part of the code actually works.

    What might be the problem here?
     
  2. Offline

    arrexe

    I believe you have to call rs.first() before you can use rs.next(). This will point the rs to the first entry, and you must handle it before you enter your while loop, as calling rs.next() right after rs.first() will skip the first value.
     
  3. your result set is closed by the close call to sql, so you cant close the result set, because its already closed
     
    bennie3211 likes this.
Thread Status:
Not open for further replies.

Share This Page