From: tomas.johansson@agent25.se
To: pgsql-jdbc@postgresql.org
Subject: NullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function
Date: 18 Oct 2004 07:39:12 -0700
Message-ID: <2e107e13.0410180639.70aea0e0@posting.google.com> (raw)
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'
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: tomas.johansson@agent25.se
Subject: Re: NullPointerException in ResultSetMetaData getColumnCount when using on a resultset from a stored function
In-Reply-To: <2e107e13.0410180639.70aea0e0@posting.google.com>
References: <2e107e13.0410180639.70aea0e0@posting.google.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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