博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Log4jdbc demo
阅读量:6304 次
发布时间:2019-06-22

本文共 4278 字,大约阅读时间需要 14 分钟。

 

package log4jdbc;import java.sql.Connection;import java.sql.PreparedStatement;import org.junit.Test;import com.mchange.v2.c3p0.ComboPooledDataSource;public class DataSourceTest {    @Test    public void testC3P0() {        try {            ComboPooledDataSource dataSource = new ComboPooledDataSource();            dataSource.setUser("root");            dataSource.setPassword("密码");            dataSource.setDriverClass("net.sf.log4jdbc.DriverSpy");            dataSource.setJdbcUrl("jdbc:log4jdbc:mysql://localhost:3306/实例名");            dataSource.setMaxPoolSize(50);            Connection conn = dataSource.getConnection();            String sql = "select * " + "from tb_person where id=?";            PreparedStatement ps = null;            ps = conn.prepareStatement(sql);            ps.setInt(1, 1);            ps.executeQuery();            ps.close();            conn.close();        } catch (Exception e) {            e.printStackTrace();        }    }}

log4j.xml

Console输出:

log4j:ERROR No appender named [connection-appender] could be found.2015-09-22 22:40:38.933 DEBUG debug: ... log4jdbc initializing ...2015-09-22 22:40:38.934 DEBUG debug:   log4jdbc.properties not found on classpath2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.debug.stack.prefix is not defined2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.sqltiming.warn.threshold is not defined2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.sqltiming.error.threshold is not defined2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.dump.booleanastruefalse is not defined (using default value false)2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.dump.sql.maxlinelength is not defined (using default of 90)2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.dump.fulldebugstacktrace is not defined (using default value false)2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.statement.warn is not defined (using default value false)2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.dump.sql.select is not defined (using default value true)2015-09-22 22:40:38.934 DEBUG debug: x log4jdbc.dump.sql.insert is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.dump.sql.update is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.dump.sql.delete is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.dump.sql.create is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.dump.sql.addsemicolon is not defined (using default value false)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.auto.load.popular.drivers is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.trim.sql is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.trim.sql.extrablanklines is not defined (using default value true)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.suppress.generated.keys.exception is not defined (using default value false)2015-09-22 22:40:38.935 DEBUG debug: x log4jdbc.drivers is not defined2015-09-22 22:40:38.942 DEBUG debug:   FOUND DRIVER com.mysql.jdbc.Driver2015-09-22 22:40:38.945 DEBUG debug: ... log4jdbc initialized! ...

工程目录下logs/sql.log

-----> 2015-09-22 22:40:39.241 
com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:379)2. select * from tb_person where id=1

http://blog.csdn.net/alex1314159/article/details/47185365

http://sourceforge.net/projects/c3p0/?source=typ_redirect
https://github.com/arthurblake/log4jdbc

 

你可能感兴趣的文章
我的友情链接
查看>>
用sqlplus远程连接oracle命令
查看>>
多年一直想完善的自由行政审批流程组件【2002年PHP,2008年.NET,2010年完善数据设计、代码实现】...
查看>>
自动生成四则运算题目
查看>>
【翻译】使用新的Sencha Cmd 4命令app watch
查看>>
【前台】【单页跳转】整个项目实现单页面跳转,抛弃iframe
查看>>
因为你是前端程序员!
查看>>
数据库设计中的14个技巧
查看>>
Android学习系列(5)--App布局初探之简单模型
查看>>
git回退到某个历史版本
查看>>
ecshop
查看>>
HTML5基础(二)
查看>>
在GCE上安装Apache、tomcat等
查看>>
在Mac 系统下进行文件的显示和隐藏
查看>>
ue4(c++) 按钮中的文字居中的问题
查看>>
技能点
查看>>
读书笔记《乌合之众》
查看>>
Hadoop日记Day1---Hadoop介绍
查看>>
iOS 学习资料汇总
查看>>
centos7 yum安装jdk
查看>>