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,
> Statement.RETURN_GENERATED_KEYS);
> java.sql.ResultSet rs = stmt.getGeneratedKeys();
> if (rs.next())
> 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
Oracle
http://www.mysql.com/products/enterprise/monitor.html

Options: ReplyQuote


Subject
Written By
Posted
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.