Re: Problem with getGeneratedKeys
Posted by: Mark Matthews
Date: April 26, 2005 10:32AM

Martin Dubuc wrote:
> I am trying to use the getGeneratedKeys function
> to get an AUTO_INCREMENT key value after
> insertion. In my current environment, I always
> get an empty result set (Connector J 3.1.7 and
> MySQL 5.0.4-beta) even though the row is actually
> inserted in the database. However, when I use the
> same Java application, but with MySQL 4.0.23a, the
> result set is not empty. Is this a problem limited
> to 5.0.4-beta?
> Here is the code:
> Statement stmt =
> con.createStatement(java.sql.ResultSet.TYPE_FORWAR
> D_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE);
> updateSQL = "INSERT INTO table (data) VALUES
> (0)";
> stmt.executeUpdate(updateSQL,
> java.sql.ResultSet rs = stmt.getGeneratedKeys();
> if (
> key = rs.getInt(1);
> else
> System.err.println("Can't retrieve key.");
> Version of Java is 1.4.2.

What's the DDL for your table?

Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools

Options: ReplyQuote

Written By
Re: Problem with getGeneratedKeys
April 26, 2005 10:32AM

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.