Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting a row when there is a sequence in that table

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually define the default value for the column to be the nextval function and let it default to that upon an insert.
 
Dave Salter
Ranch Hand
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hehe that was really easy then. Thanks a lot to both of you, you saved me some precious time
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic