JDBC driver. Class Cast Exception when calling CallableStatement.getShort

From: "Federico Fissore" <fissore(at)hyphen(dot)it>
To: pgsql-bugs(at)postgreSQL(dot)org
Subject: JDBC driver. Class Cast Exception when calling CallableStatement.getShort
Date: 2004-11-07 17:54:47
Message-ID: 20041107175449.6FBD03A3BC8@svr1.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

As subject, i got a stored function that returns an int2
i successfully call it using a callable statement, exactly as it is written in the manual, but when the getShort expression is executed, i receive a "Exception in thread Exception in thread "Timer-1" java.lang.ClassCastException: java.lang.Short
at org.postgresql.jdbc2.AbstractJdbc2Statement.getShort(AbstractJdbc2Statement.java:1681)
at org.jcpo.Classes.DBProxy.getIssueStatus(DBProxy.java:131)
at org.jcpo.Classes.Issue.getIssueStatus(Issue.java:402)
at org.jcpo.Classes.Issue.canGoOn(Issue.java:431)
at org.jcpo.Classes.SenderPostOffice.canGoOn(SenderPostOffice.java:109)
at org.jcpo.Classes.SenderPostOffice.run(SenderPostOffice.java:70)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)

I thought about a workaround and tried to call it using a Types.INTEGER, instead of Types.SMALLINT, but, CORRECTLY, the jdbc driver tells me:
A CallableStatement function was executed and the return was of type java.sql.Types=5 however type java.sql.Types=4 was registered.

I'm using pgdev.307.jdbc3 driver with a PostgreSQL Database Server 8.0.0-beta4

I saw in the source code of the driver that, to obtain a short, an Object is casted to Integer and a (short) Integer.getValue() is called, this way
(short)((Integer)callResult).intValue ()
I don't know if a Integer.shortValue() would work

The code I've used follows

The Java code
CallableStatement cstm = conn.prepareCall("{? = call myFunction(?)}");
cstm.registerOutParameter(1,Types.SMALLINT);
cstm.setInt(2, anObject.getIntVar());
cstm.execute();
short shortResult = cstm.getShort(1);
cstm.close();

The PG SQL function
CREATE OR REPLACE FUNCTION myFunction(int4) RETURNS int2 AS
$BODY$
SELECT shortCol
FROM aTable
$BODY$
LANGUAGE 'sql' VOLATILE;

Best regards

Federico

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Federico Fissore 2004-11-07 18:28:51 Re: JDBC driver. Class Cast Exception when calling CallableStatement.getShort
Previous Message contact 2004-11-07 13:03:36 installation according to C:\Applications\cygwin\usr\share\doc\postgresql-7.4.3\FAQ_MSWIN