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)
Class.forName("com.mysql.jdbc.Driver").newInstance();
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()));
insertRow.executeUpdate();
ResultSet rs = insertRow.getGeneratedKeys();
if(!rs.next())
System.out.println("Could not get generated key");
else
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
Subject
Written By
Posted
December 09, 2004 10:11AM
December 09, 2004 11:50AM
Re: getGeneratedKeys returns an empty resultset
December 09, 2004 12:25PM
December 10, 2004 08:23AM
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.