将 Oracle 的 DBMS_APPLICATION_INFO 包与 Spring JDBC 结合使用

发布于 2024-10-10 09:59:18 字数 597 浏览 0 评论 0原文

目前,我们的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮光之海 2024-10-17 09:59:18

您研究过 Spring Aspects 吗?

Have you looked into Spring Aspects?

被你宠の有点坏 2024-10-17 09:59:18

我的问题的答案是否定的。如果我今天要解决这个问题,我可能会考虑为 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.

岁月流歌 2024-10-17 09:59:18

可能是因为您写的是 DMBS_APPLICATION_INFO 而不是 DBMS_APPLICATION_INFO(注意“DMBS”而不是“DBMS”) )。

Maybe because you wrote DMBS_APPLICATION_INFO and not DBMS_APPLICATION_INFO (note "DMBS" and not "DBMS").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文