From: | Christian Niles <christian(at)unit12(dot)net> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | ClassCastException in getShort(int) |
Date: | 2004-10-21 18:12:04 |
Message-ID: | B65963E7-238C-11D9-83CE-000A9590B78E@unit12.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hi All,
I've found a bug in AbstractJdbc1Statement.getShort(int) which causes a
ClassCastException. I noticed that this file has been deleted in the
public CVS, and have confirmed that the bug exists in
AbstractJdbc2Statement.
The bug seems to be that getShort(int) casts the Short to an Integer:
public short getShort(int parameterIndex) throws SQLException
{
checkClosed();
checkIndex (parameterIndex, Types.SMALLINT, "Short");
if (callResult == null)
return 0;
return (short)((Integer)callResult).intValue ();
}
[ from
http://gborg.postgresql.org/project/pgjdbc/cvs/co.php/pgjdbc/org/
postgresql/jdbc2/AbstractJdbc2Statement.java?sa=1&r=1.36 ]
All the other methods seem to cast the appropriate type, except
getByte(int), which also casts to Integer (I haven't tested
getByte(int) though).
I checked the return value using getObject(int) and the result object
is indeed a java.lang.Short.
FYI, I'm using the 215 build for 7.4 (pg74.215.jdbc3.jar). I don't
suspect my code has anything to do with the problem, but here it is:
private short db_getLibraryID(String library) throws SQLException {
CallableStatement stmt = connection.prepareCall("{?= call
get_library_id(?) }");
stmt.registerOutParameter(1, Types.SMALLINT);
stmt.setString(2, library);
stmt.execute();
return stmt.getShort(1);
}
best,
christian.
From | Date | Subject | |
---|---|---|---|
Next Message | Kris Jurka | 2004-10-21 18:27:48 | [GENERAL] JDBC +CIDR (fwd) |
Previous Message | Dave Cramer | 2004-10-21 16:44:58 | Re: A couple of questions |