我想用一個表創建一個簡單的SQL數據庫。第8行拋出一個SQLSyntaxErrorException。創建表拋出SQL異常
public class LoadDatabase {
public static void main(String[] args) {
//if createConnection() returns a connection issue SQL Statements
try (Connection connection = ConnectToDatabase.createConnection()){
Statement command = connection.createStatement();
//gives SQL command "create table" to database
command.executeUpdate(ConnectToDatabase.CREATE_TABLE);
command.close();
} catch (ClassNotFoundException e) {
System.err.println("Could not find database driver");
} catch (SQLException e) {
System.err.println("SQL Error");
e.printStackTrace();
}
}
}
這是表
//SQL command to create a new table as constant variable
public final static String CREATE_TABLE =
"CREATE TABLE BOOK_INVENTORY (" +
"TITLE VARCHAR, " +
"AUTHOR VARCHAR, " +
"PAGES INT, " +
"ISBN VARCHAR, " +
")";
不確定在列表列表中是否允許拖尾','。 – luk2302
您的'ISBN'列後面有一個尾部','。 – Siyual
@ luk2302這是不允許的 –