File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and Relational Databases 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 Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 457
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: 3740
    
  10

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


[OCA 8 Book] [Blog]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we get the preset auto-increment number before any insertion
 
It's not a secret anymore!