| 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");
|
 |
 |
|
|
subject: How to insert autoincrement value?
|
|
|