开发人员可以利用Humpic JDBC Logger这个工具监控由Jdbc,Hibernate, iBatis 或其它数据访问工具所产生的SQL语句。
传统的SQL日志通常只能看到SQL语句,如“Select * from Table where name=?”, 而对里面的参数“?”没法进一步监视。
该日志库可以完美的解决这个问题,并且可以很方便的和任何系统进行集成,只要更改数据库连接参数,而不用修改代码。
下载: http://dl.dbank.com/c05x03ajyb
com.humpic.framework.debug.jdbclog.JdbcLogDriver
Description: Wrapper class for Driver.
DriverManagerDataSource ds = new DriverManagerDataSource();
// ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setDriverClassName("com.humpic.framework.debug.jdbclog.JdbcLogDriver ");
ds.setUrl("jdbc:oracle:thin:@localhost:1521:orcl");
ds.setUsername("sa");
ds.setPassword("");
The wrap driver can auto identify following drivers.
- MySQL
- Oracle
- JTDS
- SQL Server 97/2000/2005
- DB2
- SyBase
- PostgreSQL
- HSqlDB
- Derby
- Informix
- TimesTen
- IBM-AS400
- SAP DB
- InterBase
- JDBC-ODBC
If you use other driver, you can add real driver class name into connection url string.
Pattern: CustomizeConnectionUrl = "jdbclog" ":" [DriverClassName] ":" ConnectionUrl
.
In customize connection url, the DriverClassName is optional.
For Oracle: jdbclog:oracle.jdbc.driver.OracleDriver:jdbc:oracle:thin:@localhost:1521:orcl
If you use Jdbc Odbc Bridge
or Apache Derby
, you must use customize connection url.
For Derby: jdbclog::jdbc:derby:MyDB;user=test;password=test
日志通过 Log4J 的 debug 级别进行输出
log4j.rootCategory = INFO, CONSOLE
log4j.logger.com.humpic.framework.debug.jdbclog = DEBUG
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %-4r [%t] %-5p %F:%L - %m%n