日期:2014-05-16 浏览次数:20526 次
package com.wallimn.util; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; import org.logicalcobwebs.proxool.configuration.PropertyConfigurator; /** * * 数据库连接管理类<br/> * 编码:wallimn 时间:2009-1-5 下午08:10:52<br/> * 版本:V1.0<br/> */ public class DbManager { private static DbManager manager = new DbManager(); static{ URL url = ClassLoader.getSystemResource("proxool.properties"); try { String fileName = url.getPath(); PropertyConfigurator.configure(fileName); System.out.println("连接配置文件:"+fileName); } catch (Exception e) { e.printStackTrace(); } } public static DbManager getInstance() { return manager; } public Connection getConnection() { Connection connection = null; try { Class.forName("org.logicalcobwebs.proxool.ProxoolDriver"); connection = DriverManager.getConnection("proxool.proxool-pool"); } catch (Exception e) { e.printStackTrace(); } return connection; } }
package com.wallimn.util; import java.sql.Connection; import java.sql.SQLException; import org.apache.log4j.jdbc.JDBCAppender; public class JDBCPoolAppender extends JDBCAppender { public JDBCPoolAppender() { super(); } @Override protected Connection getConnection() throws SQLException { return DbManager.getInstance().getConnection(); } }
package com.wallimn.test; import org.apache.log4j.Logger; import org.apache.log4j.MDC; import junit.framework.TestCase; public class Log4JTest extends TestCase { public void testLog1() { Logger logger = Logger.getLogger("SYSTEM"); // System.out.println(Log4JTest.class); System.out.println("继承:" + logger.getAdditivity()); System.out.println("级别:" + logger.getLevel()); System.out.println("有效的级别:" + logger.getEffectiveLevel()); MDC.put("