wood burning stoves 2.0*
The moose likes JDBC 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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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,
I agree. Here's the link: http://aspose.com/file-tools
subject: MySQL field is autoincrememnt - insert?
Similar Threads
Locking/Unlocking, -- Am I Done Or I Don't Understand Requirements?
recNo choice
how to know the last auto-increment number using JDBC
NX:[URLyBird]How can I use the flexible way to implement RMI data access?
How to handle this situation