Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java and mysql retrieving the auto increment value

 
peter m hayward
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can specify it at the time of creating a PreparedStatement - Connection.prepareStatement(). An example below -

You can retrieve it using Statement.getGeneratedKeys()
 
peter m hayward
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic