[JDBC] PreparedStatement and identity column Hi to all,
I’ve a table with an idendity column :
CREATE TABLE USRDB2.MYTABLE (
"ID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0,
INCREMENT BY 1, NO CACHE),
"CODE" CHARACTER (3),
PRIMARY KEY (ID))IN MYTS01@
I would like to execute the following request (which works in a db2cmd):
db2 insert into usrdb2.mytable (id, code) values (DEFAULT, 'AD') @
with JDBBC:
String REQUEST = "insert into usrdb2.mytable (id, code) values (?, ?)";
PreparedStatement stmt = connection. prepareStatement(REQUEST);
stmt.setInt(1,...);
stmt.setString(2, 'AD');
stmt.execute();
but I don't know how. I got the error SQL0798N : A value cannot be
specified for column "ID" which is defined as GENERATED ALWAYS
Thanks a lot for your answers
Dov |