Subject | Re: How to call Stored procedure? |
---|---|
Author | Roman Rokytskyy <rrokytskyy@yahoo.co.uk> |
Post date | 2002-12-14T17:07:30Z |
> Please give me a working example that calls an 'exec type' stored(id
> procedure like this:
>
> create procedure AddRec(cdate timestamp, name varchar(80)) returns
> integer) asPreparedStatement stmt = connection.prepareStatement(
> begin
> id = GEN_ID(G_Tab1ID, 1);
> insert into Tab1(ID, Name, CDate) values (:ID, :Name, :CDate);
> end
"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