[ 
https://issues.apache.org/jira/browse/DERBY-6948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075675#comment-16075675
 ] 

Rick Hillegas commented on DERBY-6948:
--------------------------------------

I have linked this issue to DERBY-3609. This is another example of the fact 
that Derby does not really support getGeneratedKeys(). In its defense, Derby 
doesn't claim to. In fact the return value of 
DatabaseMetaData.supportsGetGeneratedKeys() is false, as can be see by running 
the following script:

{noformat}
connect 'jdbc:derby:memory:db;create=true';

call syscs_util.syscs_register_tool( 'databaseMetaData', true );

values supportsGetGeneratedKeys();
{noformat}

> INSERT .. SELECT produces NULL for getGeneratedKeys()
> -----------------------------------------------------
>
>                 Key: DERBY-6948
>                 URL: https://issues.apache.org/jira/browse/DERBY-6948
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.13.1.1
>            Reporter: Lukas Eder
>
> The following code:
> {code}
> import java.sql.Connection;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.Statement;
> import org.apache.derby.jdbc.EmbeddedDataSource;
> public class Derby {
>     public static void main(String[] args) throws Exception {
>         EmbeddedDataSource ds;
>         ds = new EmbeddedDataSource();
>         ds.setDatabaseName("memory:test;create=true");
>         try (Connection con = ds.getConnection();
>              Statement s = con.createStatement()) {
>             s.execute(
>                 "CREATE TABLE test ("
>               + "id INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY,"
>               + "name VARCHAR(255))");
>             try (PreparedStatement ps = con.prepareStatement("insert into 
> test (name) select 'a' from sysibm.sysdummy1", 
> Statement.RETURN_GENERATED_KEYS)) {
>                 ps.executeUpdate();
>                 try (ResultSet rs = ps.getGeneratedKeys()) {
>                     while (rs.next())
>                         System.out.println("GEN_ID: " + rs.getObject(1));
>                 }
>             }
>             try (PreparedStatement ps = con.prepareStatement("insert into 
> test (name) select 'a' from sysibm.sysdummy1", 
> Statement.RETURN_GENERATED_KEYS)) {
>                 ps.executeUpdate();
>                 try (ResultSet rs = ps.getGeneratedKeys()) {
>                     while (rs.next())
>                         System.out.println("GEN_ID: " + rs.getObject(1));
>                 }
>             }
>             try (ResultSet rs = s.executeQuery("select id from test")) {
>                 while (rs.next())
>                     System.out.println("    ID: " + rs.getObject(1));
>             }
>         }
>     }
> }
> {code}
> Produces this output:
> {code}
> GEN_ID: null
> GEN_ID: null
>     ID: 1
>     ID: 2
>     ID: 3
> {code}
> The expected output would be:
> {code}
> GEN_ID: 1
> GEN_ID: 2
> GEN_ID: 3
>     ID: 1
>     ID: 2
>     ID: 3
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to