pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedproblem with returning a table
3+ messages / 3 participants
[nested] [flat]
* problem with returning a table
@ 2005-03-28 09:23 Ejder DAÞKIN <1030515082@erciyes.edu.tr>
0 siblings, 1 reply; 3+ messages in thread
From: Ejder DAÞKIN @ 2005-03-28 09:23 UTC (permalink / raw)
To: pgsql-jdbc
Hi everybody,
There is a function that returns a table. I set out parameter's type
to Types.OTHER but When I call the function in java, returning type is
returned as INTEGER .
Here is the function:
CREATE OR REPLACE FUNCTION sube_getir(int4, "varchar")
RETURNS SETOF subeler AS
$BODY$
DECLARE
id ALIAS FOR $1;
ad ALIAS FOR $2;
ref record;
BEGIN
IF (id=0)AND(ad='') THEN
for ref in SELECT * FROM subeler loop
RETURN NEXT ref;
end loop;
return;
ELSEIF (ad='') THEN
for ref in SELECT * FROM subeler WHERE "HESAP_SUBE_ID"=id loop
return next ref;
end loop;
return;
ELSE
for ref in SELECT * FROM subeler WHERE "HESAP_SUBE_ADI"=ad loop
return next ref;
end loop;
return;
END IF;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION sube_getir(int4, "varchar") OWNER TO postgres;
--------calling function in java:
sc = conn.prepareCall("{ ? = call sube_getir( ? , ? ) }");
sc.registerOutParameter(1,Types.OTHER);
sc.setInt(2,4);
sc.setString(3,"");
sc.execute();
rs = (ResultSet)sc.getObject(1);
^ permalink raw reply [nested|flat] 3+ messages in thread
* problem with returning a table
@ 2005-03-28 09:29 John Smith <mtdragon@spymac.com>
0 siblings, 0 replies; 3+ messages in thread
From: John Smith @ 2005-03-28 09:29 UTC (permalink / raw)
To: pgsql-jdbc
Hi everybody,
There is a function that returns a table. I set out parameter's type
to Types.OTHER but When I call the function in java, returning type is
returned as INTEGER .
Here is the function:
CREATE OR REPLACE FUNCTION sube_getir(int4, "varchar")
RETURNS SETOF subeler AS
$BODY$
DECLARE
id ALIAS FOR $1;
ad ALIAS FOR $2;
ref record;
BEGIN
IF (id=0)AND(ad='') THEN
for ref in SELECT * FROM subeler loop
RETURN NEXT ref;
end loop;
return;
ELSEIF (ad='') THEN
for ref in SELECT * FROM subeler WHERE "HESAP_SUBE_ID"=id loop
return next ref;
end loop;
return;
ELSE
for ref in SELECT * FROM subeler WHERE "HESAP_SUBE_ADI"=ad loop
return next ref;
end loop;
return;
END IF;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION sube_getir(int4, "varchar") OWNER TO postgres;
--------calling function in java:
sc = conn.prepareCall("{ ? = call sube_getir( ? , ? ) }");
sc.registerOutParameter(1,Types.OTHER);
sc.setInt(2,4);
sc.setString(3,"");
sc.execute();
rs = (ResultSet)sc.getObject(1);
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: problem with returning a table
@ 2005-03-28 09:31 Kris Jurka <books@ejurka.com>
parent: Ejder DAÞKIN <1030515082@erciyes.edu.tr>
0 siblings, 0 replies; 3+ messages in thread
From: Kris Jurka @ 2005-03-28 09:31 UTC (permalink / raw)
To: Ejder DAÞKIN <1030515082@erciyes.edu.tr>; +Cc: pgsql-jdbc
On Mon, 28 Mar 2005, [ISO-8859-9] Ejder DAÞKIN wrote:
> There is a function that returns a table. I set out parameter's type
> to Types.OTHER but When I call the function in java, returning type is
> returned as INTEGER .
>
> CREATE OR REPLACE FUNCTION sube_getir(int4, "varchar")
> RETURNS SETOF subeler AS
>
> sc = conn.prepareCall("{ ? = call sube_getir( ? , ? ) }");
> sc.registerOutParameter(1,Types.OTHER);
> sc.setInt(2,4);
> sc.setString(3,"");
> sc.execute();
> rs = (ResultSet)sc.getObject(1);
>
http://jdbc.postgresql.org/documentation/80/callproc.html#callproc-resultset
As the documentation describes there are two methods for getting
ResultSets from a stored procedure. You have mismatched the
calling convention with the function you have written.
Kris Jurka
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-03-28 09:31 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-28 09:23 problem with returning a table Ejder DAÞKIN <1030515082@erciyes.edu.tr>
2005-03-28 09:31 ` Kris Jurka <books@ejurka.com>
2005-03-28 09:29 problem with returning a table John Smith <mtdragon@spymac.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox