how to use log4jdbc to log SQL

1. download it from http://code.google.com/p/log4jdbc/

log4jdbc4-1.2beta2.jar: for JDBC 4 (JDK 1.6 and 1.7) Featured Jun 2010 62.2 KB 4647
log4jdbc3-1.2beta2.jar: for JDBC 3 (JDK 1.4 and 1.5) Featured Jun 2010 50.4 KB 2146

I uses log4jdbc4-1.2beta2.jar donwload it ot desktop.


2. add to your maven server:
http://localhost:8081/nexus/index.html#view-repositories log in as admin/admin123
click Repositories on the left menu.
then 3rd party --> then on the bottom right panel click "Artifact Upload":

GAV Definition: GAV Parameters.
Group: net.sf.log4jdbc
Artifact: log4jdbc4
version: 1.2beta2
Packaging: jar
Then click "Select Artifacct(s) to Upload... to find the jar file.
Click "Add Artifact" button
click "Upload Artifact(s)

The artifact is stored in the nexus now. to verify it: click "Brownse Storage" --> Refresh --> net.sf..... you find it.,


3. to use it in your project:

3.1 add the pom to your pom file:
<dependency>
<groupId>net.sf.log4jdbc</groupId>
<artifactId>log4jdbc4</artifactId>
<version>1.2beta2</version>
</dependency>


3.2 suppose that you have setup slf4j log system already.

3.3 Set your JDBC driver class to
net.sf.log4jdbc.DriverSpy

in your application's configuration


3.4 Prepend log4jdbc to the normal jdbc url that you are using.

For example, if your normal jdbc url is

original: jdbc:derby://localhost:1527//db-derby-10.2.2.0-bin/databases/MyDatabase
new jdbc:log4jdbc:derby://localhost:1527//db-derby-10.2.2.0-bin/databases/MyDatabase

then You would change it to:

jdbc:log4jdbc:derby://localhost:1527//db-derby-10.2.2.0-bin/databases/MyDatabase
to use log4jdbc.

Here is the example:

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
<property name="url" value="jdbc:log4jdbc:hsqldb:mem:test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>

Original one:

<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>


// if you can do it like that, you can wrap it :


final Connection conn = ds().getConnection();
Connection connection = new net.sf.log4jdbc.ConnectionSpy(conn);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值