Re: getGeneratedKeys returns an empty resultset
Posted by: amol k
Date: December 09, 2004 12:25PM

Thanks for taking a look at the problem.
Here is the code: (column names changed. rest all is as it is)

connection = DriverManager.getConnection("jdbc:mysql://localhost/test_catalog?user=root");
insertRow = connection.prepareStatement("insert into mytable (varchar_col, int_col, numeric_col, timestamp) values (?,?,?,?)", Statement.RETURN_GENERATED_KEYS);

insertRow.setString(1, "abc");
insertRow.setInt(2, 10);
insertRow.setLong(3, 100);
insertRow.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
ResultSet rs = insertRow.getGeneratedKeys();
System.out.println("Could not get generated key");
System.out.println("generated key:"+rs.getLong(1));

Row *does* get inserted but I get the first message. i.e. "Could not get generated key"

The table mytable has 5 columns:
mytable_id - int - not null - auto inc
varchar_col - varchar(45) - not null
int_col - int - not null
numeric_col - numeric - not null
timestampt - timestamp

Options: ReplyQuote

Written By
Re: getGeneratedKeys returns an empty resultset
December 09, 2004 12:25PM

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.