Subject | CallableStatement returning same number |
---|---|
Author | Kenneth |
Post date | 2002-02-04T06:50:32Z |
Hi
I have a simple stored procedure that returns the PK ID of an inserted
record.
I've tried using CallableStatement, the code works, but seems that only the
first generator value is returned repeatedly.
Is this the expected result?
//------------------------------------------------
SET TERM ^ ;
CREATE PROCEDURE SP_TMPOBJ_INSERT
RETURNS (OBJID NUMERIC(18,0))
AS
BEGIN
OBJID = GEN_ID(GEN_TMPOBJ,1);
INSERT INTO TMP_OBJECTS (ID) VALUES (:OBJID);
SUSPEND;
END^
COMMIT WORK ^
SET TERM ;^
//------------------------------------------------
This code doesn't work (I get only the first PK ID, repeatedly)
for (int i=0; i<100; i++) {
//DOESN'T SEEM TO WORK CallableStatement cs =
con.getCallableStatement("{CALL SP_TMPOBJ_INSERT()}");
CallableStatement cs = con.getCallableStatement("EXECUTE PROCEDURE
SP_TMPOBJ_INSERT;");
//cs.registerOutParameter(1, Types.NUMERIC); //UNSUPPORTED?
cs.execute();
long lID = cs.getLong(1);
System.out.println(lID);
}
//------------------------------------------------
This code works (I get an incrementing PK ID).
for (int i=0; i<100; i++) {
PreparedStatement cs = con.prepareStatement("SELECT * FROM
SP_TMPOBJ_INSERT;");
ResultSet rs = cs.executeQuery();
rs.next();
long lID = rs.getLong(1);
System.out.println(lID);
}
I have a simple stored procedure that returns the PK ID of an inserted
record.
I've tried using CallableStatement, the code works, but seems that only the
first generator value is returned repeatedly.
Is this the expected result?
//------------------------------------------------
SET TERM ^ ;
CREATE PROCEDURE SP_TMPOBJ_INSERT
RETURNS (OBJID NUMERIC(18,0))
AS
BEGIN
OBJID = GEN_ID(GEN_TMPOBJ,1);
INSERT INTO TMP_OBJECTS (ID) VALUES (:OBJID);
SUSPEND;
END^
COMMIT WORK ^
SET TERM ;^
//------------------------------------------------
This code doesn't work (I get only the first PK ID, repeatedly)
for (int i=0; i<100; i++) {
//DOESN'T SEEM TO WORK CallableStatement cs =
con.getCallableStatement("{CALL SP_TMPOBJ_INSERT()}");
CallableStatement cs = con.getCallableStatement("EXECUTE PROCEDURE
SP_TMPOBJ_INSERT;");
//cs.registerOutParameter(1, Types.NUMERIC); //UNSUPPORTED?
cs.execute();
long lID = cs.getLong(1);
System.out.println(lID);
}
//------------------------------------------------
This code works (I get an incrementing PK ID).
for (int i=0; i<100; i++) {
PreparedStatement cs = con.prepareStatement("SELECT * FROM
SP_TMPOBJ_INSERT;");
ResultSet rs = cs.executeQuery();
rs.next();
long lID = rs.getLong(1);
System.out.println(lID);
}