aspose file tools*
The moose likes JDBC and the fly likes How to use Oracle sequence in preparedstatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to use Oracle sequence in preparedstatement" Watch "How to use Oracle sequence in preparedstatement" New topic
Author

How to use Oracle sequence in preparedstatement

Sidhu roy
Greenhorn

Joined: Aug 11, 2011
Posts: 15
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

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Nov 09, 2011
Posts: 1020
    
    5



replacing SEQUENCE_NAME with the name of your sequence.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

hi Sidhu, please read this little item sqlColumnLists
Sidhu roy
Greenhorn

Joined: Aug 11, 2011
Posts: 15
thanks James Boswell and everyone, its working.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Oracle sequence in preparedstatement