• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Sequence using sql commands

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
u can retrieve the sequence value separately like this

store the value in a variable and use it in ur insert statement.
 
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
viral,
Ignore Rajeshwari your syntax looks ok to me.
try a commit(); on the connection?
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 925
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well spotted
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic