Error with SQL and Mariadb (Current position is before the first Row)

Asked

Viewed 167 times

1

I have a problem in my database and I have no idea what it is.

public String getBlockPermission(String blockstring){
    String permission = "";
    try{
        ResultSet res = connection.createStatement().executeQuery("select permission from limitedblocks where blockstring='" + blockstring + "';");
        permission = res.getString("permission");
    }catch(Exception e){
        e.printStackTrace();
    }
    return permission;
}

Error:

java.sql.SQLDataException: Current position is before the first row
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:115)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.throwError(MariaSelectResultSet.java:566)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.checkObjectRange(MariaSelectResultSet.java:549)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.getString(MariaSelectResultSet.java:820)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.getString(MariaSelectResultSet.java:828)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at me.vitoremnoel.blocklimiter.BlockLimiter.getBlockPermission(BlockLimiter.java:240)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at me.vitoremnoel.blocklimiter.BlockLimiter.canPlace(BlockLimiter.java:250)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at me.vitoremnoel.blocklimiter.listeners.MainListeners.placeBlockEvent(MainListeners.java:33)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.listener.PlaceListener_MainListeners_placeBlockEvent7.handle(Unknown Source)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:95)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:313)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:297)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:338)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:326)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.SpongeImpl.postEvent(SpongeImpl.java:143)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.TrackingUtil.iterateChangeBlockEvents(TrackingUtil.java:629)
[04:49:08] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.TrackingUtil.processBlockCaptures(TrackingUtil.java:536)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.phase.packet.PacketFunction.lambda$null$41(PacketFunction.java:848)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.CapturedSupplier.ifPresentAndNotEmpty(CapturedSupplier.java:57)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.phase.packet.PacketFunction.lambda$static$44(PacketFunction.java:846)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.phase.packet.PacketPhase.unwind(PacketPhase.java:324)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.CauseTracker.completePhase(CauseTracker.java:226)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.CauseTracker.switchToPhase(CauseTracker.java:168)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:156)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zjj000(SourceFile:539)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at java.util.concurrent.FutureTask.run(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.util.Util.func_181617_a(SourceFile:45)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:239)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.redirect$onRun$zhp000(MinecraftServer.java:3948)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:668)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:387)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:613)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at java.lang.Thread.run(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:-1]: Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Current position is before the first row
[04:49:09] [Server thread/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:-1]:    ... 35 more
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]: java.sql.SQLDataException: Current position is before the first row
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:115)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.throwError(MariaSelectResultSet.java:566)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.checkObjectRange(MariaSelectResultSet.java:549)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.getInt(MariaSelectResultSet.java:942)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.getInt(MariaSelectResultSet.java:949)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at me.vitoremnoel.blocklimiter.BlockLimiter.placed(BlockLimiter.java:267)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at me.vitoremnoel.blocklimiter.listeners.MainListeners.placeBlockEvent(MainListeners.java:37)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.listener.PlaceListener_MainListeners_placeBlockEvent7.handle(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:95)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:313)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:297)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:338)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:326)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.SpongeImpl.postEvent(SpongeImpl.java:143)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.TrackingUtil.iterateChangeBlockEvents(TrackingUtil.java:629)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.TrackingUtil.processBlockCaptures(TrackingUtil.java:536)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.phase.packet.PacketFunction.lambda$null$41(PacketFunction.java:848)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.CapturedSupplier.ifPresentAndNotEmpty(CapturedSupplier.java:57)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.phase.packet.PacketFunction.lambda$static$44(PacketFunction.java:846)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.phase.packet.PacketPhase.unwind(PacketPhase.java:324)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.CauseTracker.completePhase(CauseTracker.java:226)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.event.tracking.CauseTracker.switchToPhase(CauseTracker.java:168)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:156)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zjj000(SourceFile:539)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at java.util.concurrent.FutureTask.run(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.util.Util.func_181617_a(SourceFile:45)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:239)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.server.MinecraftServer.redirect$onRun$zhp000(MinecraftServer.java:3948)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:668)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:387)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:613)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:placed:270]:   at java.lang.Thread.run(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:-1]: Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Current position is before the first row
[04:49:09] [Server thread/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:-1]:    ... 34 more
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]: java.sql.SQLDataException: Current position is before the first row
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:115)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.throwError(MariaSelectResultSet.java:566)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.checkObjectRange(MariaSelectResultSet.java:549)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.getString(MariaSelectResultSet.java:820)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.mariadb.jdbc.internal.queryresults.resultset.MariaSelectResultSet.getString(MariaSelectResultSet.java:828)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at me.vitoremnoel.blocklimiter.BlockLimiter.getBlockPermission(BlockLimiter.java:240)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at me.vitoremnoel.blocklimiter.listeners.MainListeners.placeBlockEvent(MainListeners.java:38)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.listener.PlaceListener_MainListeners_placeBlockEvent7.handle(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.RegisteredListener.handle(RegisteredListener.java:95)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:313)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:297)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:338)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.mod.event.SpongeModEventManager.post(SpongeModEventManager.java:326)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.SpongeImpl.postEvent(SpongeImpl.java:143)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.TrackingUtil.iterateChangeBlockEvents(TrackingUtil.java:629)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.TrackingUtil.processBlockCaptures(TrackingUtil.java:536)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.phase.packet.PacketFunction.lambda$null$41(PacketFunction.java:848)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.CapturedSupplier.ifPresentAndNotEmpty(CapturedSupplier.java:57)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.phase.packet.PacketFunction.lambda$static$44(PacketFunction.java:846)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.phase.packet.PacketPhase.unwind(PacketPhase.java:324)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.CauseTracker.completePhase(CauseTracker.java:226)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.event.tracking.CauseTracker.switchToPhase(CauseTracker.java:168)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:156)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$zjj000(SourceFile:539)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at java.util.concurrent.FutureTask.run(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.util.Util.func_181617_a(SourceFile:45)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at org.spongepowered.common.SpongeImplHooks.onUtilRunTask(SpongeImplHooks.java:239)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.redirect$onRun$zhp000(MinecraftServer.java:3948)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:668)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:387)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:613)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471)
[04:49:09] [Server thread/INFO] [STDERR/]: [me.vitoremnoel.blocklimiter.BlockLimiter:getBlockPermission:242]:   at java.lang.Thread.run(Unknown Source)
[04:49:09] [Server thread/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:-1]: Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Current position is before the first row
[04:49:09] [Server thread/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:-1]:    ... 34 more

2 answers

2

Use the next or first before capturing the value.

public String getBlockPermission(String blockstring){
    String permission = "";
    try{
        ResultSet res = connection.createStatement().executeQuery("select permission from limitedblocks where blockstring='" + blockstring + "';");

        res.first(); /* Move para primeira ocorrência */

        permission = res.getString("permission");
    }catch(Exception e){
        e.printStackTrace();
    }
    return permission;
}

1

First your code is susceptible to SQL injection and does not close the connection, the res or the statement created. See more about this in that question.

By correcting these problems, we come to this:

private static final String SQL_BLOCK_PERMISSION =
        "SELECT permission FROM limitedblocks WHERE blockstring = ?";

public String getBlockPermission(String blockString) {
    try (PreparedStatement ps = connection.prepareStatement(SQL_BLOCK_PERMISSION)) {
        ps.setString(1, blockString);
        try (ResultSet res = ps.executeQuery()) {
            if (res.next()) return res.getString("permission");
            return "";
        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

I don’t know how you create the object connection and how you manage it, but I would also suspect that it is not properly managed.

Another detail is the handling of exceptions. Capture the exception, launch a printStackTrace() and going on as if nothing happened is bad programming practice. However, having only the code you gave, there is not enough material to suggest anything better.

Finally, note the call to the method next() within the if. It is he who puts the ResultSet first position of the result, if it exists. If it does not exist, we do not enter the if and we fell into the return "";. It may be that if it does not exist, you prefer to make an exception instead. When you work with ResultSetwhich contains multiple results, it is appropriate to use a while instead of a if.

  • Importantly, the appeal Try-with-Resources is only available from Java 7.

  • VLW bro, I help me a lot, I solved all these problems.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.