Subject | Re: Stored Procedures with Resultset |
---|---|
Author | Roman Rokytskyy |
Post date | 2003-03-30T21:45:08Z |
> How do I get a result set back from a stored procedure? I wasFalse.
> expecting something like this:
>
> CREATE PROCEDURE readIdentity( oid INTEGER ) AS
> BEGIN
> SELECT * FROM Objects WHERE identity=:oid;
> END
> Then, in JDBC:False.
>
> CallableStatement st = con.prepareCall( "{call readIdentity(?)}" );
> ResultSet rs = st.executeQuery();
> I guess I am expecting it to be too easy. But I haven't found anyDocumentation can be found at
> documentation on this.
http://www.ibphoenix.com/main.nfs?a=ibphoenix&s=1049059518:29349&page=ibp_download#DOCS
If link does not work, go to www.ibphoenix.com, then Main Downloads,
then InterBase 6.0 Documentation set; it is pretty up to date.
Firebird 1.0 has some new constructs, but for the beginning this
should be ok.
Your code should look like:
CREATE PROCEDURE readIdentity (oid INTEGER) RETURNS (nameValue
VARCHAR(20), surnameValue VARCHAR(30), creationDateValue TIMESTAMP) AS
BEGIN
FOR SELECT name, surname, creationDate FROM Objects
WHERE identity = :oid
INTO :nameValue, :surnameValue, :creationDateValue
DO
SUSPEND;
END
Note, without SUSPEND command you will not get result set.
In Java you should use:
PreparedStatement ps =
con.prepareStatement("SELECT * FROM readIdentity(?)");
ps.setInt(1, 1);
ResultSet rs = ps.executeQuery();
You cannot use escaped syntax because driver always translates {call
...} into EXECUTE PROCEDURE ..., and this in turn returns only one row
(if any). We hardly can fix this in the driver, because there is no
flag that gives us a hint that procedure is selectable (at least I do
not know about it).
Best regards,
Roman Rokytskyy