db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Marr" <stefan.m...@web.de>
Subject Statment.getGeneratedKeys not implemented? or how to use it?
Date Mon, 04 Apr 2005 07:52:21 GMT
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".

Any suggestions?

May be the tables aren't set up right?


Kind Regards
Stefan Marr




Mime
View raw message