I am trying to insert a record to a table which has...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Cigdem_Cemgil
Posted On:   Tuesday, March 13, 2001 02:39 AM

I am trying to insert a record to a table which has
generated primary key. The insert statement, if it is
hard coded, seems to work. But if I use PreparedStatement,
I got "incorrect number of parameters", which is not the
case. Does PreparedStatement not work with the generated
primary keys?

Re: I am trying to insert a record to a table which has...

Posted By:   Christopher_Schultz  
Posted On:   Wednesday, April 4, 2001 11:38 AM

More information would help out a lot with this question:




  • What DB are you using?
  • What query are you executing?
  • How are you doing your auto-generated keys?



JDBC does not (yet) directly support returning auto-generated column values (a la a numeric primary key). You currently have two options:




  1. Turn around and query the database for the data you just inserted, along with the primary key column
  2. If you're using a sequence to generate your keys, you could select the next value of your sequence FIRST, and then use that to perform your INSERT query.



-chris
About | Sitemap | Contact