Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UnsupportedOperationException Statement.getGeneratedKeys()

 
David Weber
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys I am trying to retrieve the auto_incremented value from a MySQL Insert Statement,
And I keep getting the following exception:



I have googled and googled and so far no fix, have tried prepared statements as well as statements.

My code:



Any help will be great guys!, thanks in advance.

Extra Info:

Windows 7 32-bit
NetBeans 6.7
MySQL 5.1
MySQL ODBC Connecter 5.1.5
JDK 6

Regards, David
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I love error messages like these because its pretty clear what the problem is. In this case "UnsupportedOperationException" means your JDBC driver does not support this feature. Retrieving generated keys is NOT a standard feature nor is it supported by all drivers. Your only choices are to switch to a different driver (often there isn't one), switch to a different database (thats rarely an option), or find another way programmatically to deal with the problem. I actually wrote an article on this some time back: Database Key Generation in Java Applications
 
David Weber
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Scott,

My mistake was using the standard jdcb.odbc.driver instead of the mysql.jdbc.driver

Problem solved!
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The native MySQL jdbc driver for your MySQL version supports it.
If you stop using the odbc bride, and start using the jdbc driver, your code will work.

Regards, Jan

(Edit: I managed to miss the last post in the thread. Glad it's solved.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic