This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Oracle sequence in preparedstatement

 
Sidhu roy
Greenhorn
Posts: 15
  • 0
  • 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
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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