Subject | RE: [Firebird-Java] Re: Getting a reference after insert |
---|---|
Author | Ken Richard |
Post date | 2002-08-07T19:58:24Z |
My stored proc looks like this:
CREATE PROCEDURE "TABLE_INSERT"
(
"V_FIELD1" INTEGER,
"V_FIELD2" VARCHAR(2000) CHARACTER SET WIN1252
)
RETURNS
(
"PK" INTEGER
)
AS
BEGIN
PK = gen_id(Table_no_gen, 1);
insert into Team ( PK_Table, Field1, Field2)
values ( :PK,:v_Field1,:v_Field2);
SUSPEND;
END
My java code looks something like this:
String proc = "{call table_insert (?,?)}");
CallableStatement stmt = connection.prepareCall(proc);
stmt.setInt(1, 123);
stmt.setString(2, "123");
stmt.execute();
ResultSet rs = stmt.getResultSet();
if (rs.next()) {
// get the newly generated primary key
int key = rs.getInt(1);
}
I am not an interbase expert, but I am pretty sure that it won't create
synchronization problems. (At least I hope so or I have some rewriting
to do!)
CREATE PROCEDURE "TABLE_INSERT"
(
"V_FIELD1" INTEGER,
"V_FIELD2" VARCHAR(2000) CHARACTER SET WIN1252
)
RETURNS
(
"PK" INTEGER
)
AS
BEGIN
PK = gen_id(Table_no_gen, 1);
insert into Team ( PK_Table, Field1, Field2)
values ( :PK,:v_Field1,:v_Field2);
SUSPEND;
END
My java code looks something like this:
String proc = "{call table_insert (?,?)}");
CallableStatement stmt = connection.prepareCall(proc);
stmt.setInt(1, 123);
stmt.setString(2, "123");
stmt.execute();
ResultSet rs = stmt.getResultSet();
if (rs.next()) {
// get the newly generated primary key
int key = rs.getInt(1);
}
I am not an interbase expert, but I am pretty sure that it won't create
synchronization problems. (At least I hope so or I have some rewriting
to do!)