I would like to create a simple SQL database with one table. Line 8 throws a SQLSyntaxErrorException.
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();
}
}
}
This is the table
//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, " +
")";
Your sql statement is incorrect:
,
in the end.This should work: