Error with SQL and MariaDB (Current position is before the first row)

1

I have a problem with 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
    
asked by anonymous 06.01.2018 / 08:25

2 answers

2

Use 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;
}
    
06.01.2018 / 10:20
1

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

Correcting these issues, 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 do not 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. Capturing the exception, casting a printStackTrace() and following as if nothing had happened is a bad programming practice. However, having only the code you gave, there is not enough material to suggest itself better.

Finally, note the call to method next() within if . It is the one that places ResultSet in the first position of the result, if it exists. If it does not exist, we do not enter if and we fall into return ""; . It may be that in case it does not exist, you'd rather throw an exception instead. When you work with ResultSet s that contains multiple results, you may want to use while instead of if .

    
06.01.2018 / 14:36