• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

can we get the preset auto-increment number before any insertion

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

if the table is blank , how can we get the preset auto-increment number ?

i have a try on this :


it return nothing if the table have no records

even i try as follow but give me same blank result



besides in mysql , to compare the column is contains empty string, is it like this ?


thank you very much for helping

database used : mysql
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really. MySQL has the neat feature that it keeps auto-incrementing from the last insert even if you wipe the entire table. This is one of the reasons primary key management is often set as an external service in more advanced systems instead of using database features.

You could run your cod as a transaction so that you can read the value of the record after insertion while not committing the changes. JDBC has features to read the newly generated keys from previous an update statement but they are not guarenteed to work so often times people just select max id (which is dangerous too).
 
reply
    Bookmark Topic Watch Topic
  • New Topic