getGeneratedKeys problem
Posted by: Tony Walker
Date: January 06, 2005 08:52AM

I am trying to use AUTO_INCREMENT with a BIGINT field. I'm not sure it's supported, but haven't found any indication to the contrary, and inserts work ok.

However, when I try to retrieve the generated key using getLong, the call fails with a null pointer exception. Retrieving the generated key with getInt works fine. However, this table will be heavily used and I don't want to be constrained to 32 bits. Is this a bug or a feature?

To reproduce:

create table PrimaryTable ( id BIGINT NOT NULL AUTO_INCREMENT, ContextId BIGINT NOT NULL, Primary Key ( id ) )


String strInsertCmd = "insert into PrimaryTable (id, ContextId) values (?, ?)";

PreparedStatement stmt = connection.prepareStatement( strInsertCmd, Statement.RETURN_GENERATED_KEYS );

stmt.setNull( 1, Types.BIGINT );
stmt.setLong( 2, 12345 );

ResultSet rs = stmt.getGeneratedKeys();
if ( {
long lUID = rs.getLong( 1 ); // must use getInt here with MySQL??



Options: ReplyQuote

Written By
getGeneratedKeys problem
January 06, 2005 08:52AM
January 06, 2005 11:39AM
January 06, 2005 12:06PM
January 06, 2005 01:40PM
January 06, 2005 02:50PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.