• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Oracle sequence in preparedstatement

 
Sidhu roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String str="insert into table1 values(?,?)";
ps=con.prepareStatement(str);
ps.setInt(1,id);

now i want to insert sequence value int the second column of the table by using sequence.nextval , i did it using Statement but i want to do it with preparedstatement please help me
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll do it the same with PreparedStatement as you did with a Statement. There is no difference. The sequence is a database object, not a variable, therefore you don't use a parameter (bind variable) to specify it.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


replacing SEQUENCE_NAME with the name of your sequence.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Sidhu, please read this little item sqlColumnLists
 
Sidhu roy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks James Boswell and everyone, its working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic