Skip site navigation (1) Skip section navigation (2)

Calling PGSQL Stored function thru JDBC

From: Nick Selva <mavles_pgsql(at)yahoo(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Calling PGSQL Stored function thru JDBC
Date: 2004-07-30 04:18:23
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Hi everyone. I'm new here. Need the help of Guru(s)

I am trying to write some java code to leverage the
power of stored-functions is pgsql. I have created the
function in the database and tested it with a 'SELECT'
function and it seems to return the result requested.
But when I try to embed some code into my Java
program, it gives errors. I will list out everything

The stored function that i created in the database
looks like this:
CREATE FUNCTION get_state(char(1)) RETURNS varchar(20)
   my_state VARCHAR(20);
   SELECT INTO my_state name FROM statename WHERE   
RETURN my_state;
' LANGUAGE plpgsql;

I tested it in the database using the SELECT function
as below:

ttms=#SELECT get_state('D');
(1 row)

So this proves that as far as postgresql database is
concerned its working perfectly fine.

Then I wrote the some java code to read a value from
the table using JDBC ResultSet to test if my
connection thru JDBC works. And it does. So at the end
of the same program I included Callable statemenet
code to call the function get_state() from the program
to receive the return value. I have attached the
program with this email. The file is called as Please do review my novice code. I can
compile and even run the bytecode. But it only runs
without any errors until it reaches the
CallableStatement portion. Then the program ends
abrubtly catching exception. The following is the
error message.
Exception caught.
org.postgresql.util.PSQLException: PostgreSQL only
supports function return value [@ 1] (no OUT or INOUT
org.postgresql.util.PSQLException: PostgreSQL only
supports function return value [@ 1] (no OUT or INOUT
        at sample.<init>(
        at sample.main(

I don't think so it's the problam with the JDBC
driver, coz if it was, it wouldn't succeed in getting
the values for the ResultSet in the earlier portion of
the code. I suppose I am missing out something in the
syntax or in the code.

Anyone have come across this? Please don't tell me
jdbc cant work with pgsql stored function coz im
planning to write half the application logic using
stored function.
Somebody please shed some light in this matter.

I thank in advance for the help rendered. Will wait
for the reply.

Best Regards,


Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage! 

Description: application/octet-stream (2.4 KB)


pgsql-jdbc by date

Next:From: Kris JurkaDate: 2004-07-30 06:31:23
Subject: Re: Calling PGSQL Stored function thru JDBC
Previous:From: Oliver JowettDate: 2004-07-30 00:03:25
Subject: Re: Bug in 7.4_213 driver: returns VARCHAR instead of

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group