| Author |
UnsupportedOperationException Statement.getGeneratedKeys()
|
David Weber
Greenhorn
Joined: Nov 03, 2009
Posts: 9
|
|
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
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
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
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
David Weber
Greenhorn
Joined: Nov 03, 2009
Posts: 9
|
|
Thanks Scott,
My mistake was using the standard jdcb.odbc.driver instead of the mysql.jdbc.driver
Problem solved!
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
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.)
|
OCUP UML fundamental
ITIL foundation
|
 |
 |
|
|
subject: UnsupportedOperationException Statement.getGeneratedKeys()
|
|
|