将 Oracle 的 DBMS_APPLICATION_INFO 包与 Spring JDBC 结合使用
目前,我们的 Web 应用程序直接对 Oracle 数据库进行 JDBC 调用。我们通过静态 getConnection(String client) 方法中对 DBMS_APPLICATION_INFO 包的调用来标记每个连接,例如,
CallableStatement pstmt = conx.prepareCall("{call DMBS_APPLICATION_INFO.SET_CLIENT_INFO(?)}");
pstmt.setString(1, "my client");
pstmt.executeUpdate();
这已被证明有时很有用,并且当我们切换到 Spring JDBC 时,我们希望继续这样做。
我认为,如果我们将每个查询设为一个事务,然后在执行查询(或多个查询)之前调用 DBMS_APPLICATION_INFO,这将可行,但这需要将上述代码添加到我们现在获得连接的每个位置。在事务之外,这似乎是不可能的,因为 Spring JDBC 会打开和关闭与每个查询的连接。
在 Spring JDBC 中,有没有一种方法可以像我们现在一样在后台调用 DBMS_APPLICATION_INFO,传递一个用于标记连接的字符串?
谢谢!
Our webapps currently make JDBC calls to our Oracle database directly. We tag each connection with calls to the DBMS_APPLICATION_INFO package in a static getConnection(String client) method, e.g.
CallableStatement pstmt = conx.prepareCall("{call DMBS_APPLICATION_INFO.SET_CLIENT_INFO(?)}");
pstmt.setString(1, "my client");
pstmt.executeUpdate();
This has proven useful from time to time, and we'd like to continue this when we switch to Spring JDBC.
I think if we made each query a transaction, then make calls to DBMS_APPLICATION_INFO before executing the query (or queries) this would work, but that would require adding the above code to every place we get a connection now. Outside of a transaction it doesn't seem possible because Spring JDBC opens and closes the connection with each query.
In Spring JDBC is there a way to make calls to DBMS_APPLICATION_INFO under the hood like we do now, passing a String with which to tag the connection?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您研究过 Spring Aspects 吗?
Have you looked into Spring Aspects?
我的问题的答案是否定的。如果我今天要解决这个问题,我可能会考虑为 Tomcat 的 JDBC 池编写拦截器或包装驱动程序。但实际上,我很可能会放弃使用 DBMS_APPLICATION_INFO。虽然很高兴拥有它,但它在操作上没有什么用处,但不值得为其添加代码和复杂性。
The answer to my question is no. If I was tackling this issue today I'd probably look at writing an Interceptor for Tomcat's JDBC pool or wrapping the driver. In reality, though, most likely I'd drop the use of DBMS_APPLICATION_INFO. While nice to have it wasn't operationally useful, not worth adding code and complexity for.
可能是因为您写的是
DMBS_APPLICATION_INFO
而不是DBMS_APPLICATION_INFO
(注意“DMBS”而不是“DBMS”) )。Maybe because you wrote
DMBS_APPLICATION_INFO
and notDBMS_APPLICATION_INFO
(note "DMBS" and not "DBMS").