aspose file tools*
The moose likes JDBC and the fly likes can we get the preset auto-increment number before any insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "can we get the preset auto-increment number before any insertion" Watch "can we get the preset auto-increment number before any insertion" New topic
Author

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

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
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
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

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).


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we get the preset auto-increment number before any insertion