I want to make use of postgres CopyManager
like:
CopyManager cp = ((PGConnection) dataSource.getConnection()).getCopyAPI();
As I'm using spring-boot
, the datasource is a org.apache.tomcat.jdbc.pool.DataSource
, thus the connection a Jdbc4Connection
.
Problem: The casting throws the following error:
java.lang.ClassCastException: com.sun.proxy.$Proxy55 cannot be cast to org.postgresql.PGConnection
Also, when I try to cast to a Jdbc4Connection, I get the very same error!
java.lang.ClassCastException: com.sun.proxy.$Proxy55 cannot be cast to org.postgresql.jdbc4.Jdbc4Connection
What can I do?
If you are using javax.sql.DataSource then here is a solution:
if (dataSource.getConnection().isWrapperFor(PGConnection.class)) {
PGConnection pgConnection = dataSource.getConnection().unwrap(PGConnection.class);
}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With