package common.sql;
import java.util.*;
public class GeneralDb {
private static Hashtable dbPool;
public static MyDB getInstance(String dbname) {
if (dbPool == null) {
dbPool = new Hashtable();
}
MyDB db = (MyDB) dbPool.get(dbname);
if (db == null) {
db = new MyDB(dbname);
dbPool.put(dbname, db);
}
return db;
}
}
Log4j数据库连接池的配置如下:
log4j.appender.JDBC=common.log.JDBCPoolAppender
log4j.appender.JDBC.sqlname=log
log4j.appender.JDBC.layout=org.apache.log4j.PatternLayout
log4j.appender.JDBC.sql=INSERT INTO LOGGING (log_date, log_level,
location, message) VALUES ('%d{ISO8601}', '%-5p', '%C,%L', '%m')
poolman.xml配置如下:
〈?xml version="1.0" encoding="UTF-8"?>
〈poolman>
〈management-mode>local〈/management-mode>
〈datasource>
〈dbname>log〈/dbname>
文章来源于领测软件测试网 https://www.ltesting.net/