| Author |
inserting a row when there is a sequence in that table
|
Celinio Fernandes
Ranch Hand
Joined: Jun 28, 2003
Posts: 546
|
|
Hi, What is the best way to insert a row in a table that has a column which values are based on a sequence (my_seq.nextval) ? In SQL, that would be: insert into mytable (toto, message) values (maseq.nextval, "hello"); but how do you handle the nextval in a JDBC statement ? Can anyone please provide me with some sample code to do that ? Thanks ! [ August 16, 2005: Message edited by: Max longbeach ]
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56150
|
|
|
I usually define the default value for the column to be the nextval function and let it default to that upon an insert.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Dave Salter
Ranch Hand
Joined: Jul 20, 2005
Posts: 292
|
|
Try using a PreparedStatement with SQL of the format: All you need to do then is set the value of the message field in the prepared statement.
|
 |
Celinio Fernandes
Ranch Hand
Joined: Jun 28, 2003
Posts: 546
|
|
hehe that was really easy then. Thanks a lot to both of you, you saved me some precious time
|
 |
 |
|
|
subject: inserting a row when there is a sequence in that table
|
|
|