public static boolean sentBan(String username, long time, String reason) { DatabaseConnection connection = World.getConnectionPool().nextFree(); if (connection == null) return false; try { Statement stmt = connection.createStatement(); ResultSet user = stmt .executeQuery("SELECT * FROM `vbulletin_user` WHERE username = '" + username + "'"); if (user.next()) { int userId = user.getInt("userid"); int groupId = user.getInt("usergroupid"); int displaygroupid = 0; String usertitle = user.getString("usertitle"); int customtitle = 0; int adminid = 1; long bandate = System.currentTimeMillis() / 1000; long liftdate = time; /* Inserting the bans */ String sql = "INSERT INTO vbulletin_userban (userid, usergroupid, displaygroupid, usertitle, customtitle, adminid, bandate, liftdate, reason) " + "VALUES ('" + userId + "', '" + groupId + "', '" + displaygroupid + "', '" + usertitle + "', '" + customtitle + "', '" + adminid + "', '" + bandate + "', '" + liftdate + "')"; stmt.execute(sql); return true; } } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { connection.returnConnection(); } } return false; }
I'm receiving this stacktrace when I try to use the above code.
java.sql.SQLException: Column count doesn't match value count at row 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2713) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2663) at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:888) at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:730) at com.mysthalin.game.player.content.custom.ForumActions.sentBan(ForumActions.java:60) at com.mysthalin.game.player.content.Commands.processModCommand(Commands.java:690) at com.mysthalin.game.player.content.Commands.processCommand(Commands.java:68) at com.mysthalin.networking.decoders.WorldPacketsDecoder.processPackets(WorldPacketsDecoder.java:1709) at com.mysthalin.networking.decoders.WorldPacketsDecoder.decode(WorldPacketsDecoder.java:289) at com.mysthalin.networking.ServerChannelHandler.messageReceived(ServerChannelHandler.java:98) at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:88) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:558) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:553) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:84) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:471) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:332) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
This is the structure of the table:
What am I doing wrong?