简体   繁体   English

如何在org.springframework.jdbc.CannotGetJdbcConnectionException上记录JDBC连接信息

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

I'm working on an application which uses the Spring framework in combination with Ibatis and a C3P0 Connection pool. 我正在开发一个将Spring框架与Ibatis和C3P0连接池结合使用的应用程序。 The system connects to about 12 seperate databases. 系统连接到大约12个单独的数据库。

When one of the databases is unreachable, I get a stacktrace in the logfile which is generated by Spring (see below). 当其中一个数据库无法访问时,我在Spring生成的日志文件中获得了堆栈跟踪(请参见下文)。 However, this logging is missing very vital information on WHICH of the databases can not be reached. 但是,此日志记录缺少关于数据库WHICH的非常重要的信息。

Basically, I would like the jdbc connection string (sans Passwords) to be logged upon connection errors. 基本上,我希望在连接错误时记录jdbc连接字符串(无密码)。 Is there an easy way to tell Spring to log this? 有没有一种简单的方法可以告诉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)

.... ....

You could enable logging in the ORM layer of Spring, like so (assuming you use log4j): 您可以像这样(假设您使用log4j)在Spring的ORM层中启用日志记录:

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

You can also use P6Spy to log your database connections. 您也可以使用P6Spy记录数据库连接。

Lastly, how about setting a breakpoints on SQLException (break when this exception is thrown) in your IDE? 最后,如何在IDE中在SQLException上设置断点(抛出此异常时中断)?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.springframework.jdbc.CannotGetJdbcConnectionException - org.springframework.jdbc.CannotGetJdbcConnectionException Spring框架的MySQL连接错误(org.springframework.jdbc.CannotGetJdbcConnectionException:无法获取JDBC连接;) - Mysql connection error for Spring framework (org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; ) org.springframework.jdbc.cannotgetjdbcconnectionexception Rmi类加载器已禁用 - org.springframework.jdbc.cannotgetjdbcconnectionexception Rmi class loader disabled 线程“ main” org.springframework.jdbc.CannotGetJdbcConnectionException中的异常 - Exception in thread “main” org.springframework.jdbc.CannotGetJdbcConnectionException org.springframework.jdbc.CannotGetJdbcConnectionException:java.sql.SQLException:找不到适用于jdbc:mysql的驱动程序 - org.springframework.jdbc.CannotGetJdbcConnectionException: java.sql.SQLException: No suitable driver found for jdbc:mysql org.springframework.jdbc.CannotGetJdbcConnectionException,嵌套异常是java.sql.SQLException - org.springframework.jdbc.CannotGetJdbcConnectionException, nested exception is java.sql.SQLException 我如何从org.springframework.jdbc.datasource.DriverManagerDataSource类获取jdbc连接 - How can i get jdbc connection from org.springframework.jdbc.datasource.DriverManagerDataSource class org.springframework.security.authentication.InternalAuthenticationServiceException:无法获取JDBC连接 - org.springframework.security.authentication.InternalAuthenticationServiceException: Could not get JDBC Connection 如何记录JDBC连接活动? - How to log JDBC connection activity? 如何加载 org.springframework.jdbc.core.RowMapper 库 - how to load org.springframework.jdbc.core.RowMapper library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM