aspose file tools*
The moose likes JDBC and the fly likes How to use Sequence using sql commands 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 Sequence using sql commands" Watch "How to use Sequence using sql commands" New topic
Author

How to use Sequence using sql commands

viral patel
Greenhorn

Joined: Feb 25, 2003
Posts: 16
Im trying to insert data to my Accounts table. I have Created AccountId_sequence to generate accountID. I'm getting data from a form and and storing in database.Here how i'm trying to insert new data with sequence, but its not updating table. Can someone show me right way to do this.
Rajeshwari Natarajan
Ranch Hand

Joined: Mar 05, 2003
Posts: 67
u can retrieve the sequence value separately like this

store the value in a variable and use it in ur insert statement.


regards<br />Rajeshwari. N
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
viral,
Ignore Rajeshwari your syntax looks ok to me.
try a commit(); on the connection?
Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
u are using
stmt.executeUpdate (" INSERT INTO Accounts (firstName, lastName, mailAdress, Zipcode) VALUES (accountID_sequence.NEXTVAL,'"+firstName+"','"+lastName+"','"+address+"','"+zipCode+"')");
But, the number of columns are diferent to the number of values, I mean, you should use :
(id, firstName, lastName, mailAdress, Zipcode)
where id is the name of the column where you want to insert the value of the sequence.
Hope this helps.
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
well spotted
 
jQuery in Action, 2nd edition
 
subject: How to use Sequence using sql commands