• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MySQL field is autoincrememnt - insert?

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic