It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes MySQL field is autoincrememnt - insert? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySQL field is autoincrememnt - insert?" Watch "MySQL field is autoincrememnt - insert?" New topic

MySQL field is autoincrememnt - insert?

Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
I'm writing a record to a table in a MySQL database. The field is set up to autoincrement.
How do I handle this?
When I write my PreparedStatement, do I include a placeholder?
tableName.setInt(1,??? what do I put here? I don't know what this value will be?)
Do I have to lock the table, get the highest value, increment by one, unlock the table, add my record (and hope nobody wrote a record between my unlock and my write)?
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

on your insert using PreparedStatement, pretend like the column doesn't exist. eg. table emp has 2 columns-->id(auto-increment) and name(text/varchar/etc)

works for me on MSAccess,
Have you checked out Aspose?
subject: MySQL field is autoincrememnt - insert?
It's not a secret anymore!