我正在开发一个将Spring框架与Ibatis和C3P0连接池结合使用的应用程序。该系统连接到大约12个单独的数据库。
当其中一个数据库无法访问时,我在Spring生成的日志文件中得到一个堆栈跟踪(见下文)。但是,此日志记录缺少关于无法访问数据库的重要信息。
基本上,我希望在连接错误时记录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)
...
答案 0 :(得分:0)
您可以在Spring的ORM层中启用日志记录,如此(假设您使用log4j):
log4j.logger.org.springframework.orm =微量,DEBUGLOG
您还可以使用P6Spy记录数据库连接。
最后,在IDE中如何在SQLException上设置断点(在抛出此异常时中断)?