*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Sequence using sql commands
 
Similar Threads
jsp and jdbc
how to get primary key after doing an insert
Table data does not appear after inserting it to the JTable
Search using Hibernate criteria querry
jsp insert into database error(java.lang.NumberFormatException: For input string: "")