File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to insert autoincrement value? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to insert autoincrement value?" Watch "How to insert autoincrement value?" New topic
Author

How to insert autoincrement value?

Marcin Kwiatkowski
Ranch Hand

Joined: Aug 06, 2007
Posts: 32

Hello, I've got a problem with this piece of code:



after I call this method SQLException is thrown: "Failed on insert row"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Don't include the autoincrement column in your insert statement and it should work fine.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Marcin Kwiatkowski
Ranch Hand

Joined: Aug 06, 2007
Posts: 32

well... when i dont include first column i got this exception :/
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Count the number of '?' in your insert statement. Are you trying to define one for the autoincrement column? The number of parameters to be bound should be one less than the number of fields in the table (since the database will populate the autoincrement field, you don't have to).
Sylven Yip
Ranch Hand

Joined: Aug 30, 2007
Posts: 42
set the auto increment field to null
e.g.
suppose id is an auto increment field
insert into table(id,name) values(null,"aldsf");

if preparedstatement
insert into table(id,name) values(null,?);

pStmt.setString(1,"aldsf");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to insert autoincrement value?
 
Similar Threads
Can we output the real SQL statments on CMP entity bean ejbCreate?
Setting values using jdbc appender log4j
problem in copying table
comparing values from database and from a textbox
Column count doesn't match value count at row 1