在没有ENUM的情况下创建表的成功,我得到了这个例外 在Java中使用Derby数据库
Statement stmt = con.createStatement();
String sql = "CREATE TABLE Coupon (ID BIGINT, TITLE VARCHAR(100), START_DATE DATE, END_DATE DATE, AMOUNT INTEGER, "
+ " TYPE ENUM('Electronics','Health','Beauty','Restaurants','Leisure','Travel'),"
+ " MESSAGE VARCHAR(40), PRICE DOUBLE, IMAGE VARCHAR(100),PRIMARY KEY(ID))";
stmt.executeUpdate(sql);
例外:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 113.
at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.client.am.ClientStatement.executeUpdate(Unknown Source)
at a.creatingTables.BuildCouponTable.main(BuildCouponTable.java:27)
Caused by: ERROR 42X01: Syntax error: Encountered "(" at line 1, column 113.
at org.apache.derby.client.am.ClientStatement.completeSqlca(Unknown Source)
at org.apache.derby.client.am.ClientStatement.completeExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseEXCSQLIMMreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.StatementReply.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.net.NetStatement.readExecuteImmediate_(Unknown Source)
at org.apache.derby.client.am.ClientStatement.readExecuteImmediate(Unknown Source)
at org.apache.derby.client.am.ClientStatement.flowExecute(Unknown Source)
at org.apache.derby.client.am.ClientStatement.executeUpdateX(Unknown Source)
... 2 more
答案 0 :(得分:0)
尝试使用此查询添加size
代替type
,如下所示:
String sql = "CREATE TABLE Coupon (ID BIGINT, TITLE VARCHAR(100), START_DATE DATE, END_DATE DATE, AMOUNT INTEGER, "
+ " size ENUM('Electronics','Health','Beauty','Restaurants','Leisure','Travel'),"
+ " MESSAGE VARCHAR(40), PRICE DOUBLE, IMAGE VARCHAR(100),PRIMARY KEY(ID))";