dbTalk Databases Forums  

[BUGS] JDBC driver. Class Cast Exception when calling CallableStatement.getShort

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] JDBC driver. Class Cast Exception when calling CallableStatement.getShort in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Federico Fissore
 
Posts: n/a

Default [BUGS] JDBC driver. Class Cast Exception when calling CallableStatement.getShort - 11-07-2004 , 11:58 AM






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.getSho rt(AbstractJdbc2Statement.java:1681)
at org.jcpo.Classes.DBProxy.getIssueStatus(DBProxy.ja va:131)
at org.jcpo.Classes.Issue.getIssueStatus(Issue.java:4 02)
at org.jcpo.Classes.Issue.canGoOn(Issue.java:431)
at org.jcpo.Classes.SenderPostOffice.canGoOn(SenderPo stOffice.java:109)
at org.jcpo.Classes.SenderPostOffice.run(SenderPostOf fice.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

Reply With Quote
  #2  
Old   
Federico Fissore
 
Posts: n/a

Default Re: [BUGS] JDBC driver. Class Cast Exception when calling CallableStatement.getShort - 11-07-2004 , 12:31 PM






i forgot
executing the function manually leads to no errors


Quote:
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.getSho rt(AbstractJdbc2Statement.java:1681)
at org.jcpo.Classes.DBProxy.getIssueStatus(DBProxy.ja va:131)
at org.jcpo.Classes.Issue.getIssueStatus(Issue.java:4 02)
at org.jcpo.Classes.Issue.canGoOn(Issue.java:431)
at org.jcpo.Classes.SenderPostOffice.canGoOn(SenderPo stOffice.java:109)
at org.jcpo.Classes.SenderPostOffice.run(SenderPostOf fice.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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.