Subject Re: How to call Stored procedure?
Author Roman Rokytskyy <rrokytskyy@yahoo.co.uk>
> 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(?, ?)");

stmt.setTimestamp(1, new Timestamp(myTime));
stmt.setString(2, myName);

ResultSet rs = stmt.executeQuery();
if (!rs.next())
throw new SomeBadException("This should never happen!");

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);

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