X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 164773A5DC0 for ; Sun, 5 Dec 2004 19:11:57 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48648-06 for ; Sun, 5 Dec 2004 19:11:53 +0000 (GMT) Received: from main.gmane.org (main.gmane.org [80.91.229.2]) by svr1.postgresql.org (Postfix) with ESMTP id 210713A5CA3 for ; Sun, 5 Dec 2004 19:11:53 +0000 (GMT) Received: from root by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1Cb1nT-00052d-00 for ; Sun, 05 Dec 2004 20:11:51 +0100 Received: from 1-1-2-48a.rny.sth.bostream.se ([82.182.133.12]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 Dec 2004 20:11:51 +0100 Received: from thhal by 1-1-2-48a.rny.sth.bostream.se with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 Dec 2004 20:11:51 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Hallgren Subject: Re: prepared statement call fails Date: Sun, 05 Dec 2004 20:08:54 +0100 Lines: 42 Message-ID: <41B35CC6.2030800@mailblocks.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 1-1-2-48a.rny.sth.bostream.se User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.186 tagged_above=0 required=5 tests=AWL, DNS_FROM_AHBL_RHSBL X-Spam-Level: X-Archive-Number: 200412/19 X-Sequence-Number: 11685 Larry White wrote: > I'm hoping someone with more experience can help me find a problem in > calling a function from Java. This is the first time I'm trying this > so I'm guessing it will be straightforward. > > The function's signature is: > > add_country(bigint, char(2), char(3), varchar(60)) > RETURNS INTEGER ' > > It works fine if I call it from the command line, like so... > > select add_country(124,'US', 'USA', 'United States of America'); > > In java, I call it using the following: > > CallableStatement proc = null; > proc = connection.prepareCall("{ ? = call add_country( ? ? ? ? ) }"); > proc.registerOutParameter(1, java.sql.Types.INTEGER); > proc.setInt(2, 124); > proc.setString(3, code2); // a two character java String > proc.setString(4, code3); // a three character java String > proc.setString(5, name); // a Java String > proc.execute(); > AFAIK, CallableStatement is for stored procedure calls. Stored procedures are not yet implemented in PostgreSQL. It only has functions. In order to call a function you need a select statement and a normal PreparedStatement. Try this: PreparedStatement stmt = connection.prepareStatement("select add_country(?,?,?,?)"); stmt.setInt(1, 124); stmt.setString(2, code2); stmt.setString(3, code3); stmt.setString(4, code4); ResultSet rs = stmt.executeQuery(); if(rs.next()) result = rs.getInt(1); Kind regards, Thomas Hallgren