簡體   English   中英

如何在org.springframework.jdbc.CannotGetJdbcConnectionException上記錄JDBC連接信息

[英]How to log JDBC connection info on org.springframework.jdbc.CannotGetJdbcConnectionException

我正在開發一個將Spring框架與Ibatis和C3P0連接池結合使用的應用程序。 系統連接到大約12個單獨的數據庫。

當其中一個數據庫無法訪問時,我在Spring生成的日志文件中獲得了堆棧跟蹤(請參見下文)。 但是,此日志記錄缺少關於數據庫WHICH的非常重要的信息。

基本上,我希望在連接錯誤時記錄jdbc連接字符串(無密碼)。 有沒有一種簡單的方法可以告訴Spring記錄此信息?

Invocation of init method failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
        at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy.getConnection(TransactionAwareDataSourceProxy.java:109)
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
        at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:183)
        at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:242)

....

您可以像這樣(假設您使用log4j)在Spring的ORM層中啟用日志記錄:

log4j.logger.org.springframework.orm = trace,debugLog

您也可以使用P6Spy記錄數據庫連接。

最后,如何在IDE中在SQLException上設置斷點(拋出此異常時中斷)?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM