I have a table in Derby constructed like this:
CREATE TABLE orders(
order_id int not null GENERATED ALWAYS AS IDENTITY primary key(START WITH 1, INCREMENT BY 1),
foreign key(cust_id) references customers(cust_id),
order_date date(yyyy-mm-dd),
order_desc varchar(128)
);
I have a servlet connected to a JSP page that takes some input and puts it into a prepared statement:
String addOrder = "INSERT INTO orders (cust_id, order_date, order_desc) VALUES (?, CURRENT_DATE, ?)";
PreparedStatement insertOrder = con.prepareStatement(addOrder);
insertOrder.setInt(1, custID);
insertOrder.setString(2, description);
insertOrder.executeUpdate();
insertOrder.close();
However, this gives me this error:
java.sql.SQLIntegrityConstraintViolationException: Column 'ORDER_ID' cannot accept a NULL value.
...
java.sql.SQLSyntaxErrorException: 'LAST_INSERT_ID' is not recognized as a function or procedure.
I have tried adding order_id
in the insert statement and giving it a value of default
but I still get the Column 'ORDER_ID' cannot accept a NULL value.
error.
Shouldn't the table increment the order_id
column automatically since it's set that way? I'm not sure what's missing.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…