my dog learned polymorphism*
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL field is autoincrememnt - insert?" Watch "MySQL field is autoincrememnt - insert?" New topic
Author

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)?
Thanks,
Pres
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,
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySQL field is autoincrememnt - insert?