Re: 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: Re: JDBC driver. Class Cast Exception when calling CallableStatement.getShort
Date: 2004-11-07 18:28:51
Message-ID: 20041107182851.A2C8B3A3BF1@svr1.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

i forgot :)
executing the function manually leads to no errors

> Da: "Federico Fissore" <fissore(at)hyphen(dot)it>
> Data: Sun, 07 Nov 2004 17:54:47 +0000
> A: pgsql-bugs(at)postgresql(dot)org
> Oggetto: [BUGS] JDBC driver. Class Cast Exception when calling CallableStatement.getShort
>
> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

Browse pgsql-bugs by date

  From Date Subject
Next Message Kris Jurka 2004-11-07 20:15:29 Re: JDBC driver. Class Cast Exception when calling
Previous Message Federico Fissore 2004-11-07 17:54:47 JDBC driver. Class Cast Exception when calling CallableStatement.getShort