Bukkit / Spigot MySQL语法错误

时间:2017-07-04 13:40:47

标签: mysql

首先,我搜索了很多关于这个问题的尝试了许多解决方案并且它没有用。

似乎是在制作桌子而且我不知道为什么它不起作用,它之前有效,但现在我没有改变任何东西而且它不起作用

我有这样的错误:“com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有错误;请查看与您的MariaDB服务器版本对应的手册,以便在''附近使用正确的语法第1行“

package me.joseph.murder.sql;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;

import me.joseph.murder.Main;

public class SQLConnection {
    public SQLDatabase MySQL;
    public static Connection c;

    public SQLConnection(Plugin plugin, String host, String port, String database, String username, String password) {
        this.MySQL = new SQLDatabase(plugin, host, port, database, username, password);
    }

    public void openConnection() {
        if (isConnected()) {
            closeConnection();
        }
        try {
            c = this.MySQL.openConnection();

            executeUpdate(
                    "CREATE TABLE IF NOT EXISTS Account (playername VARCHAR(16), wins INT(10), loses INT(10), deaths INT(10), kills INT(10), coins INT(10);");
            new BukkitRunnable() {
                @Override
                public void run() {
                    SQLConnection.this.openConnection();
                }
            }.runTaskLater(Main.getInstance(), 100L);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public boolean isConnected() {
        try {
            if (c.isClosed()) {
                return false;
            }
            return true;
        } catch (Exception e) {
        }
        return false;
    }

    public void closeConnection() {
        if (isConnected()) {
            try {
                c.close();
            } catch (SQLException localSQLException) {
            }
        }
    }

    public ResultSet executeQuery(String statement, boolean next) {
        if (isConnected()) {
            try {
                Statement s = c.createStatement();
                ResultSet res = s.executeQuery(statement);
                if (next) {
                    res.next();
                }
                return res;
            } catch (SQLException e) {
                return null;
            }
        }
        return null;
    }

    public boolean executeUpdate(String statement) {
        if (isConnected()) {
            try {
                Statement s = c.createStatement();
                s.executeUpdate(statement);
                return true;
            } catch (SQLException e) {
                e.printStackTrace();
                return false;
            }
        }
        return false;
    }
}

1 个答案:

答案 0 :(得分:0)

缺少括号;)

CREATE TABLE IF NOT EXISTS
Account (
    playername VARCHAR(16),
    wins INT(10),
    loses INT(10),
    deaths INT(10),
    kills INT(10),
    coins INT(10)
);