ClassCastException in getShort(int)

Поиск
Список
Период
Сортировка
От Christian Niles
Тема ClassCastException in getShort(int)
Дата
Msg-id B65963E7-238C-11D9-83CE-000A9590B78E@unit12.net
обсуждение исходный текст
Ответы Re: ClassCastException in getShort(int)  (Kris Jurka <books@ejurka.com>)
Список 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.


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: [GENERAL] JDBC +CIDR (fwd)
Следующее
От: Christian Niles
Дата:
Сообщение: Calling functions with smallint fails