我一直在使用MySQL一段時間,並且出於某種奇怪的原因,無論是在我的代碼中是否有一些我沒有看到的NPE,或者只是我忘了,我得到的錯誤是我之前沒有的MySQL在創建表時引發異常,但僅在Java中引發異常?
static MySQL sql = Essentials.getinstance().sql;
public static String TABLE_MAIN = "`PlayerStats`";
public static String TABLE_GROUP = "`Groups`";
public static String TABLE_BUILDNG = "`Build`";
public static String TABLE_ARCHERY = "`Archer`";
public static String TABLE_DIGGING = "`Dig`";
public static String TABLE_MINING = "`Mine`";
public static String TABLE_FARMING = "`Farm`";
public static String TABLE_WOODCUTTIN = "`Wood`";
public static String TABLE_FIGHTING = "`Combat`";
public static String KEY = "`Player`";
public static String LEVEL = "`Level`";
public static String XP = "`XP`";
public static String[] tables = new String[] { TABLE_MAIN, TABLE_ARCHERY, TABLE_BUILDNG, TABLE_DIGGING, TABLE_FARMING, TABLE_FIGHTING, TABLE_MINING, TABLE_WOODCUTTIN };
public PlayerStats() {
this.start();
this.setName("RPG-Setup");
}
@Override
public void run() {
for(String table : tables){
sql.updateSQL("CREATE TABLE IF NOT EXISTS " + table + "(" + KEY + " varchar(128), " + LEVEL + " bigint, " + XP + " bigint, PRIMARY KEY(" + KEY + "))");
}
sql.updateSQL("CREATE TABLE IF NOT EXISTS `Groups` (`Player` varchar(128), `Group` varchar(64), PRIMARY KEY(`Player`))");
}
整個類是更長的時間,但是這是什麼引發錯誤:
sql.updateSQL("CREATE TABLE IF NOT EXISTS `Groups` (`Player` varchar(128), `Group` varchar(64), PRIMARY KEY(`Player`))");
什麼是沒有意義就是爲什麼。它不是拋NPE,而是拋出:
[19:55:42 WARN]: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQ L server version for the right syntax to use near '' at line 1
任何想法?
對這個問題沒有任何評論,但是命名一個「Group」列是一個糟糕的壞主意。這是所有數據庫中的保留字。使用你的想象力,並提出一個更好的名字。 –
這不是「壞,壞,壞主意」。這只是「壞主意」。你需要明白你在做什麼,因爲你可以有名爲'group'的列沒有很多問題。 –