我正在尝试使用 Java 在我的 sqlite 数据库中创建表。但它在最后一个表 ORDER 上不断出现语法错误 >_<,该表有 2 个外键。
...我不确定我做错了什么,有人可以检查并告诉我我的错误吗?
继承人的代码:
public boolean CreateTables() {
Connection cn = getConnected();
String createCategory = "Create table Category("
+ "id text primary key not null,"
+ "name text not null,"
+ "deliverday int not null,"
+ "isdelete bit not null"
+ ")";
String createCustomer = "Create table Customer("
+ "id text primary key not null,"
+ "name text not null,"
+ "email text not null,"
+ "phone text not null,"
+ "address text not null,"
+ "isdelete boolean not null"
+ ")";
String createOrder = "Create table Order("
+ "id text primary key not null,"
+ "custid text references Category(id) no null,"
+ "catid text references Customer(id) not null,"
+ "orderdate date not null,"
+ "delieverdate date not null,"
+ "description text not null,"
+ "requirement text not null,"
+ "price int not null,"
+ "image text not null,"
+ "product text not null,"
+ "state text not null,"
+ ")";
try {
PreparedStatement pst;
try {
System.out.println("*** Create table Category");
pst = cn.prepareStatement(createCategory);
pst.executeUpdate();
pst.close();
System.out.println("*** Category created Successfully");
} catch (Exception e) {
System.out.println("*** Failed to create Category");
System.out.println(e.getMessage());
}
try {
System.out.println("*** Create table Customer");
pst = cn.prepareStatement(createCustomer);
pst.executeUpdate();
pst.close();
System.out.println("*** Customer created Successfully");
} catch (Exception e) {
System.out.println("*** Failed to create Customer");
System.out.println(e.getMessage());
}
try {
System.out.println("*** Create table Order");
pst = cn.prepareStatement(createOrder);
pst.executeUpdate();
pst.close();
System.out.println("*** Order created successsfully");
} catch (Exception e) {
System.out.println("*** Failed to create Order");
System.out.println(e.getMessage());
}
System.out.println("*** COMPLETE CREATING TABLE PROCESS ****");
cn.close();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
这是错误。
*** Start to connection Sqlite
*** Connected to Sqlite successfully
*** Create table Category
*** Category created Successfully
*** Create table Customer
*** Customer created Successfully
*** Create table Order
*** Failed to create Order
[SQLITE_ERROR] SQL error or missing database (near "Order": syntax error)
*** COMPLETE CREATING TABLE PROCESS ****