aspose file tools*
The moose likes JDBC and the fly likes java and mysql retrieving the auto increment value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java and mysql retrieving the auto increment value" Watch "java and mysql retrieving the auto increment value" New topic
Author

java and mysql retrieving the auto increment value

peter m hayward
Ranch Hand

Joined: Sep 27, 2012
Posts: 31
I have tried lots of examples non of which fit my particular situation to retrieve the auto incremented value that is generated as a result of inserting a row into the mysql database here is my code with a work around that does the trick but the section that start String doesAuthorExist2 seems unnecessary if i could use either getGeneratedKeys() or 'SELECT LAST_INSERT_ID()'; which i have attempted to use with out success
T Mishra
Ranch Hand

Joined: Apr 04, 2006
Posts: 107

You can specify it at the time of creating a PreparedStatement - Connection.prepareStatement(). An example below -

You can retrieve it using Statement.getGeneratedKeys()


Thanks,
Tushar (SCJP 1.5)
peter m hayward
Ranch Hand

Joined: Sep 27, 2012
Posts: 31
T Mishra wrote:You can specify it at the time of creating a PreparedStatement - Connection.prepareStatement(). An example below -

You can retrieve it using Statement.getGeneratedKeys()


Thank you this is just what i needed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java and mysql retrieving the auto increment value
 
Similar Threads
prepared statement
How to configure Bonecp in java project without breaking connection when more than connection
doubt in update
using database connection in jframes
prepared statement