开发者

How can I access the database native java.sql.Connection?

I'm using WASCE as application server and defined a data source to PosgreSQL. I get the DB Connection from JNDI.

The problem is I want to access specific method in the PostgreSQL java.sql.Connection but WASCE wrapped this connection with their own Connection.

Specifically, I want to do something like this:

((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");

Is that possible? If yes, please share how.

EDIT:

I expect to have something like access to the original Connection from this wrapped Connection, but I can't find any un开发者_如何学JAVAtil now.


Generally connections will be handled through a pool. In order to be handled (relatively) transparently you will get a proxy to the real connection. Therefore, you cannot successfully cast the connection directly. The connection pool may have an API that allows you to get to the underlying connection.


You can try

((PooledConnection) conn).getConnection()

Or, since Java 1.6:

conn.unwrap(...)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜