java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.jdbc4.Jdbc4Connection
- by ???????? ??????
I want to get PGConnection from posgresql connection in JBOSS AS7 (Data source postgresql-9.0-801.jdbc4.jar)
I've got cast exception when used (WrappedConnection)connection
So now I use reflection(JDK 1.7):
private static PGConnection getPGConnection(Connection connection) throws SQLException {
if(connection instanceof PGConnection) {
return (PGConnection)connection;
}
try {
Class[] parms = null;
Method method =(connection.getClass()).getMethod("getUnderlyingConnection", parms);
return (PGConnection) jdbc4Conn;
} catch ...
and catch exception
java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Connection cannot be cast to org.postgresql.jdbc4.Jdbc4Connection
It is the same class!!!
Haw could it be?