Yes the approach is fragile and I have experienced a problem using
C3P0 connection pooling because the java.sql.Connection implementation
that it supplies is a generated proxy and can never be cast to an
oracle.jdbc.driver.OracleConnection nor can the native connection be
obtained because the Connection interface, quite rightly, supports no
such method. However I have found that the DatabaseMetaData instance
returned from a call to getMetaData on this Connection proxy does
return the native/original connection when you call its getConnection
() method. How about that. Have not tried this on any other connection
pooling implementations though but it might be worth a go.
eg
DatabaseMetaData dbMetaData = st.getConnection().getMetaData
().getConnection()
seems bizarre I know but it works.
Paul Branscombe |