Hi
I get the following error:
org.postgresql.util.PSQLException: A CallableStatement function was
executed and the return was of type java.sql.Types=12 however type
java.sql.Types=1111 was registered.
when running the following code:
conn.setAutoCommit(false);
CallableStatement stmt = conn.prepareCall("{ ? = call
myfunction1() }");
stmt.registerOutParameter(1, Types.OTHER);
stmt.execute();
ResultSet rs = (ResultSet) stmt.getObject(1);
while (rs.next()) {
result = result + rs.getString(1);
result = result + rs.getDouble(2);
}
create type b_line as (account_text varchar(255), amount numeric);
CREATE OR REPLACE FUNCTION myfunction1()
RETURNS setof b_line AS
$BODY$DECLARE
tmp1 numeric;
account RECORD;
r b_line%rowtype;
BEGIN
tmp1 = 0.00;
FOR i IN 30..39 LOOP
FOR account IN SELECT id, account_id, name, type, amount_cred FROM
bo.obj_ledger WHERE account_id like (i || '__') ORDER BY id LOOP
IF account.type = 'P' THEN
tmp1 = tmp1 + account.amount_cred;
ELSE
tmp1 = tmp1 - account.amount_cred;
END IF;
END LOOP;
END LOOP;
r.account_text = 'Line1:';
r.amount = tmp1;
return next r;
RETURN;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
I'm using the following versions:
pg80b1.308.jdbc3.jar
PostgreSQL 8.0.0rc1 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC)
3.3.1 (mingw special 20030804-1)
Thanks for your help.
Regards,
Jerome