db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Jaster <bobj5...@yahoo.com>
Subject autogenerated keys do not work with single column table
Date Tue, 26 Sep 2006 03:39:34 GMT
I have discovered that if I create a table with only one column, such as
   
  CREATE TABLE mo.company (
 id      BIGINT    NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
 PRIMARY KEY (id)
);
   
  then execute 
   
    String sql = "INSERT INTO mo.company VALUES (DEFAULT)";
  PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
    preparedStatement.executeUpdate();
    ResultSet resultSet = preparedStatement.getGeneratedKeys();
    System.out.println("resultSet.next()==" + resultSet.next());
  Object object = resultSet.getObject(1);
  if (object == null) {
   System.out.println("object is null");
  } else {
   long id = resultSet.getLong(1);
   System.out.println("id==" + id);
  }

  I always get null returned from resultSet.getObject(1), whereas if I add a second column
to the table (a VARCHAR(100)) then I get the generated key value.
  
Is this a bug?
   
  Bob Jaster
   
   

 		
---------------------------------
Do you Yahoo!?
 Get on board. You're invited to try the new Yahoo! Mail.
Mime
View raw message