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

Re: CallableStatement: java.sql.Types=12 however type

From: Kris Jurka <books(at)ejurka(dot)com>
To: Jerome Colombie <jcolombie(at)gmx(dot)ch>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: CallableStatement: java.sql.Types=12 however type
Date: 2004-12-21 21:35:25
Message-ID: Pine.BSO.4.56.0412211632270.19588@leary.csoft.net (view raw or flat)
Thread:
Lists: pgsql-jdbc

On Tue, 21 Dec 2004, Jerome Colombie wrote:

> org.postgresql.util.PSQLException: A CallableStatement function was 
> executed and the return was of type java.sql.Types=12 however type 
> java.sql.Types=1111 was registered.
> 
> when running the following code:
> 
>                conn.setAutoCommit(false);
>                 CallableStatement stmt = conn.prepareCall("{ ? = call 
> myfunction1() }");
>                 stmt.registerOutParameter(1, Types.OTHER);
>                 stmt.execute();
>                 ResultSet rs = (ResultSet) stmt.getObject(1);
>                 while (rs.next()) {
>                     result = result + rs.getString(1);
>                     result = result + rs.getDouble(2);
>                 }
> 
> create type b_line as (account_text varchar(255), amount numeric);
> 
> CREATE OR REPLACE FUNCTION myfunction1()
>   RETURNS setof b_line AS

The JDBC driver is expecting a single scalar value returned from your 
function.  It retrieves the first column in the first row and detects that 
it is a varchar, not the Types.OTHER that you had registered.  You really 
don't want to use the CallableStatement interface for this operation.  Try 
instead:

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM myfunction()");

Kris Jurka


In response to

Responses

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2004-12-22 11:26:44
Subject: Re: Bug in JDBC-Driver?
Previous:From: Jerome ColombieDate: 2004-12-21 21:19:11
Subject: CallableStatement: java.sql.Types=12 however type java.sql.Types=1111 was registered

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