Solved Error in SQL syntax

Discussion in 'Spigot Plugin Development' started by HockeyFreak062, Jul 8, 2021.

  1. Hey! I'm trying to create tables in my SQL database. But when I start the server up I get this error:

    [12:38:32] [Server thread/WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(LOCATION))' at line 1
    [12:38:32] [Server thread/WARN]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [12:38:32] [Server thread/WARN]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(
    [12:38:32] [Server thread/WARN]: at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(
    [12:38:32] [Server thread/WARN]: at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(
    [12:38:32] [Server thread/WARN]: at java.base/java.lang.reflect.Constructor.newInstance(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.Util.handleNewInstance(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.Util.getInstance(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.SQLError.createSQLException(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.MysqlIO.checkErrorPacket(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.MysqlIO.sendCommand(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.ConnectionImpl.execSQL(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.PreparedStatement.executeInternal(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(
    [12:38:32] [Server thread/WARN]: at com.mysql.jdbc.PreparedStatement.executeUpdate(
    [12:38:32] [Server thread/WARN]: at Main.SQL.SQLGetter.createTable(
    [12:38:32] [Server thread/WARN]: at Main.Main.onEnable(
    [12:38:32] [Server thread/WARN]: at
    [12:38:32] [Server thread/WARN]: at
    [12:38:32] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(
    [12:38:32] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugin(
    [12:38:32] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_17_R1.CraftServer.enablePlugins(
    [12:38:32] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.loadWorld(
    [12:38:32] [Server thread/WARN]: at net.minecraft.server.dedicated.DedicatedServer.init(
    [12:38:32] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.x(
    [12:38:32] [Server thread/WARN]: at net.minecraft.server.MinecraftServer.lambda$0(
    [12:38:32] [Server thread/WARN]: at java.base/

    My code here is:
    Code (Java):

    private Main plugin;
    public SQLGetter(Main plugin){
        this.plugin = plugin;

    public void createTable(){
        PreparedStatement ps;
        PreparedStatement ps1;

            ps = plugin.SQL.getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS prisons "
                    + "(NAME VARCHAR(100), UUID VARCHAR(100), XP INT(100), LEVEL INT(100), MONEY INT(100)," +
                    " COAL INT(100), IRON INT(100), LAPIS INT(100), GOLD INT(100), DIAMOND INT(100)" +
                    ", EMERALD INT(100) PRIMARY KEY (NAME))");
           [Line26 of Main.SQL.SQLGetter] ps.executeUpdate();
            ps1 = plugin.SQL.getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS locations " +
                    "(LOCATION VARCHAR(100), X INT(100), Y INT(100), Z INT(100)," +
                    " YAW INT(100), PITCH INT(100) PRIMARY KEY (LOCATION))");
        } catch (SQLException e){

    if (SQL.isConnected()){
        Bukkit.getLogger().info("Database is connected!");
        [Line 50 in Main] data.createTable();
    I hope someone can help me, Database is starting up. First time of starting the plugin it created the "prisons" table, after the next restarts it gave me this error and does not create the "Locations" table....
  2. Hi, what is on line 26?
  3. You forgot the comma before the primary key
  4. You need a comma before that PRIMARY KEY statement.
    You can use sites like this to check and validate your statements:
  5. Omg im so stupid.... Thanks! This solved it :D
    • Like Like x 1