如何访问数据库本机java.sql.Connection?
我使用 WASCE 作为应用程序服务器,并定义了 PosgreSQL 的数据源。我从 JNDI 获取数据库连接。
问题是我想访问 PostgreSQL java.sql.Connection 中的特定方法,但 WASCE 用自己的 Connection 包装了此连接。
具体来说,我想做这样的事情:
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
这可能吗?如果是,请分享如何。
编辑:
我希望能够从这个包装的连接访问原始连接,但直到现在我还找不到任何东西。
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 until now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常连接将通过池来处理。为了(相对)透明地处理,您将获得真实连接的代理。因此,您无法直接成功转换连接。连接池可能有一个 API,允许您访问底层连接。
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.
你可以尝试
或者,从 Java 1.6 开始:
You can try
Or, since Java 1.6: