【发布时间】:2016-11-30 02:01:23
【问题描述】:
我不确定为什么我的程序没有创建表格,但我还需要一些关于如何在表格创建后用这样的代码填充表格的想法?我还需要在这个数据库中再添加两个表。
这是我得到的错误:
java.sql.SQLSyntaxErrorException: Table/View 'PIZZASIZE' does not exist.
Caused by: ERROR 42X05: Table/View 'PIZZASIZE' does not exist.
Caused by: java.lang.RuntimeException: Exception in Application start method
Caused by: javafx.fxml.LoadException: file:/C:/Users/Allie/Documents/NetBeansProjects/Pizzeria_AllieBeckman/dist/run1674141987/Pizzeria_AllieBeckman.jar!/pizzeria_alliebeckman/FXMLDocument.fxml
这是应该创建表的代码:
// connect to the derby URL using the given username and password
connect = DriverManager.getConnection("jdbc:derby://localhost:1527/pizzeria;create=true", connectProps);
// current url for pre created database "jdbc:derby://localhost:1527/pizza"
// if connection is successful print that it succeeded.
System.out.println("database created");
stmt = connect.createStatement();
String sqlCreate = "CREATE TABLE PIZZASIZE "
+ "(id int NOT NULL, "
+ "size char(20) NOT NULL, "
+ "PRIMARY KEY (id))";
stmt.execute(sqlCreate);
【问题讨论】:
-
试试
stmt.executeUpdate(sqlCreate) -
与 stmt.executeUpdate(sqlCreate) 相同的错误 :(
-
System.out.println("database created");这被执行了吗? -
是的,确实可以打印
标签: java sql database database-connection derby