Subject Re: [Firebird-Java] Re: How to call Stored procedure?
Author Andrew Guts
Roman Rokytskyy wrote:

>>Please give me a working example that calls an 'exec type' stored
>>procedure like this:
>>
>>create procedure AddRec(cdate timestamp, name varchar(80)) returns
>>
>>
>(id
>
>
>>integer) as
>>begin
>> id = GEN_ID(G_Tab1ID, 1);
>> insert into Tab1(ID, Name, CDate) values (:ID, :Name, :CDate);
>>end
>>
>>
>
>PreparedStatement stmt = connection.prepareStatement(
> "SELECT id FROM AddRec(?, ?)");
>
Ok. It will work, but will not return output parameter, because SP was
written as 'executable'. The SP body does not contain "SUSPEND"
operator. That is why "select " syntax will not return any results in
such manner:

>int myId = rs.getInt(1)
>

>another example would be:
>
>CallableStatement stmt = connection.prepareCall(
> "{call AddRec(?, ?)}");
>
>stmt.setTimestamp(1, new Timestamp(myTime));
>stmt.setString(2, myName);
>
>stmt.execute();
>
>int myId = stmt.getInt(1);
>
I've tried it before asking my question. I've seen only an error
message, something like this: "SQL Error code -104. Token unknown -
line 1, char 1 { "
After I had replaced operator to "execute procedure AddRec(?, ?)" it
worked, but still no output parameter.
Adding third parameter and registerOutputParameter here causes exception
"Not implemented yet".

>
>But I do not like this example, because call statement is not 100%
>correct. It should be "{call AddRec(?, ?, ?)}" and we should call
>stmt.registerOurParameter(3, Types.INTEGER) after preparing a call.
>However, Firebird API makes it hard to support JDBC specification in
>this case.
>
>Best regards,
>Roman Rokytskyy
>
>
>
So should I rewrite the SP as selectable? Any other ideas?

Thank you for your answer.

Andrew