繁体   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