db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mamta Satoor <msat...@gmail.com>
Subject Re: Statment.getGeneratedKeys not implemented? or how to use it?
Date Tue, 05 Apr 2005 23:52:43 GMT
On Apr 3, 2005 11:52 PM, Stefan Marr <stefan.marr@web.de> wrote:
> Hi,
> 
> I'm trying to get a little practice using derby with JDBC.
> So I've begin to do some "standard" SQL stuff.
> 
> Unfortunately I get in trouble with my real first INSERT-statement.
> 
> I'd like to have an auto-increment column for ids and get the id from the
> done insert.
> 
> http://incubator.apache.org/derby/manuals/reference/sqlj229.html
> or
> http://publib.boulder.ibm.com/infocenter/cldscp10/index.jsp?topic=/com.ibm.c
> loudscape.doc/sqlj229.htm
> 
> told me, this should be possible.
> 
> My test database is set up with the following lines:
> 
> stmt.execute("CREATE TABLE personen (person_id INTEGER NOT NULL GENERATED
> ALWAYS AS IDENTITY, person_name VARCHAR(100), person_ort VARCHAR(32),
> PRIMARY KEY (person_id))");
> 
> stmt.execute("CREATE TABLE daten (datum_id INTEGER NOT NULL GENERATED ALWAYS
> AS IDENTITY, person_id INTEGER, datum_value TIMESTAMP, datum_typ SMALLINT,
> PRIMARY KEY (datum_id))");
> 
> Now I'm trying to insert:
> 
> stmt.execute("insert into personen (person_name, person_ort) values
> ('peter', 'london')", Statement.RETURN_GENERATED_KEYS);
> 
> And get the Id:
> 
> genIds = stmt.getGeneratedKeys();
> modifiedId = genIds.getInt(0);
> 
> On the last line I'm getting an error instead of the value :(
> I've also tried genIds.getInt("person_id");
> 
> In the documentation is written an array with name or column index should
> work to, so I'd try the following:
> 
> String[] colIndexes = new String[1];
> colIndexes[0] = "person_id";
> 
> or
> 
> int[ ] colIndexes = new int[1];
> colIndexes[0] = 1; //or 0
> 
> stmt.execute("insert into personen (person_name, person_ort) values
> ('peter', 'london')", colIndexes);
> 
> But now I'm getting a "not implemented".

Hi Criag,

As for passing array of column names or column indexes, the
documentation is incorrect. I will file a Jira entry for it. Derby
does not support passing array of column names or column indexes in
conjuction with Statement.getGeneratedKeys.

Mamta

Mime
View raw message