pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedNullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function
3+ messages / 2 participants
[nested] [flat]
* NullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function
@ 2004-10-18 14:39 Tomas <tomas.johansson@agent25.se>
2004-10-18 20:21 ` Re: NullPointerException in ResultSetMetaData getColumnCount Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 3+ messages in thread
From: tomas.johansson@agent25.se @ 2004-10-18 14:39 UTC (permalink / raw)
To: pgsql-jdbc
How can you get metadata from a resultset that is returned from a
stored function ?
I have tried the code below with the latest "pg74.215.jdbc3.jar" at
http://jdbc.postgresql.org/download.html
but the invocation of metaData.getColumnCount()) below will lead to a
NullPointerException:
java.lang.NullPointerException
at org.postgresql.jdbc2.AbstractJdbc2ResultSetMetaData.getColumnCount(AbstractJdbc2ResultSetMetaData.java:34)
private void testCallable(Connection conn) throws Exception
{
CallableStatement call = conn.prepareCall("{ ? = call
myfunction() }");
call.registerOutParameter(1, Types.OTHER);
call.execute();
ResultSet results = (ResultSet) call.getObject(1);
ResultSetMetaData metaData = results.getMetaData();
System.out.println("getColumnCount: " +
metaData.getColumnCount());
results.close();
call.close();
}
CREATE TABLE public.mytable
(
mycolumn int4,
mycolumn2 int4
)
CREATE OR REPLACE FUNCTION public.myfunction()
RETURNS refcursor AS
'
DECLARE
ref refcursor;
BEGIN
OPEN ref FOR
SELECT mycolumn, mycolumn2 FROM mytable;
RETURN ref;
END;
'
LANGUAGE 'plpgsql'
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: NullPointerException in ResultSetMetaData getColumnCount
2004-10-18 14:39 NullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function Tomas <tomas.johansson@agent25.se>
@ 2004-10-18 20:21 ` Kris Jurka <books@ejurka.com>
2004-10-19 06:53 ` Re: NullPointerException in ResultSetMetaData getColumnCount Tomas <tomas.johansson@agent25.se>
0 siblings, 1 reply; 3+ messages in thread
From: Kris Jurka @ 2004-10-18 20:21 UTC (permalink / raw)
To: Tomas <tomas.johansson@agent25.se>; +Cc: pgsql-jdbc
On Mon, 18 Oct 2004, Tomas wrote:
> How can you get metadata from a resultset that is returned from a
> stored function ?
You need to be running with autocommit off for this to work at all. This
is not just a metadata problem. The problem is that cursors are closed at
commit, which in auto commit mode is before the results can even be
fetched from it. It could definitely use a better error message, the 8.0
driver gives "ERROR: cursor "<unnamed portal 1>" does not exist", but
that's still not very good.
Kris Jurka
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: NullPointerException in ResultSetMetaData getColumnCount
2004-10-18 14:39 NullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function Tomas <tomas.johansson@agent25.se>
2004-10-18 20:21 ` Re: NullPointerException in ResultSetMetaData getColumnCount Kris Jurka <books@ejurka.com>
@ 2004-10-19 06:53 ` Tomas <tomas.johansson@agent25.se>
0 siblings, 0 replies; 3+ messages in thread
From: tomas.johansson@agent25.se @ 2004-10-19 06:53 UTC (permalink / raw)
To: pgsql-jdbc
books@ejurka.com (Kris Jurka) wrote in message news:<Pine.BSO.4.56.0410181515590.5115@leary.csoft.net>...
> On Mon, 18 Oct 2004, Tomas wrote:
>
> > How can you get metadata from a resultset that is returned from a
> > stored function ?
>
> You need to be running with autocommit off for this to work at all. This
> is not just a metadata problem. The problem is that cursors are closed at
> commit, which in auto commit mode is before the results can even be
> fetched from it. It could definitely use a better error message, the 8.0
> driver gives "ERROR: cursor "<unnamed portal 1>" does not exist", but
> that's still not very good.
>
> Kris Jurka
Thank you Kris for your answer.
I was using the 7.4 version of the driver since the PostgreSQL version
I am using is 7.4.5 but now I tested the 8.0 driver and then the
metadata seems to work. Regarding the 7.4 driver it did not help to
change the autocommit.
/ Tomas
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2004-10-19 06:53 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-10-18 14:39 NullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function Tomas <tomas.johansson@agent25.se>
2004-10-18 20:21 ` Re: NullPointerException in ResultSetMetaData getColumnCount Kris Jurka <books@ejurka.com>
2004-10-19 06:53 ` Re: NullPointerException in ResultSetMetaData getColumnCount Tomas <tomas.johansson@agent25.se>
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