Hi,
I read in the release notes that there is a currval function to retrieve the value generated by a auto_increment column.
I tried following sql, but the currval select returned an error.
How should this be done?
Thanks
Rob
create table tst (id integer not null auto_increment, val integer default null, primary key (id))
insert into tst (val) values (100)
select currval('tst','id')
|
>How should this be done?
You doen't use SEQUENCE so that you needn't use currval.
You should use Statement.RETURN_GENERATED_KEYS. For instance,
stmt.executeUpdate("insert into tst (val) values (100);",Statement.RETURN_GENERATED_KEYS);
ResultSet rs=stmt.getGeneratedKeys();
rs.next();
System.out.println("The id for inserted row is "+rs.getObject(1));
|
But why does the currval not work?
I could not use Statement.RETURN_GENERATED_KEYS when I want to script it all
Rob
|
Checked. Yeah.
select currval(tst.id);
select currval('tst','id')
is correct according to API document.
Please download the latest package after about 3 hours.
|