最近做的OA项目,需要连接到两个数据库,我采用的方法是:利用proxool连接池进行连接;其中,主要是写了两个proxool的连接类进行分别连接数据库。今天,在写登录测试的时候,报了如下的错误:
2013-10-23 2:14:17 org.logicalcobwebs.proxool.ProxoolFacade registerConnectionPool信息: Proxool 0.9.0RC3 (10-Jan-2007 01:38)
org.logicalcobwebs.proxool.ProxoolException: Parsing failed.
at org.logicalcobwebs.proxool.configuration.JAXPConfigurator.configure(JAXPConfigurator.java:91)
at org.logicalcobwebs.proxool.configuration.JAXPConfigurator.configure(JAXPConfigurator.java:56)
at pinyou_oa.dao.BaseDao_PyWebDB.<init>(BaseDao_PyWebDB.java:37)
at pinyou_oa.dao.BaseDao.getdbweb(BaseDao.java:22)
at pinyou_oa.dao.BaseDao.<init>(BaseDao.java:11)
at pinyou_oa.dao.impl.PyUsersDaoImpl.<init>(PyUsersDaoImpl.java:11)
at pinyou_oa.action.LoginAction.<init>(LoginAction.java:14)
........... ................................ .......................................
以及:
Caused by: org.logicalcobwebs.proxool.ProxoolException: Attempt to register duplicate pool called 'mysqlpinyouweb'
at org.logicalcobwebs.proxool.configuration.XMLConfigurator.endElement(XMLConfigurator.java:198)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
从报错的信息中,可以看出是“尝试重复的注册了连接”,及上面红色的部分,一直都没有想出是哪里写错了代码,重复注册连接;直到,刚才突然间反应过来,错误的原因在于,文章的开头提到的“两个proxool的连接类进行分别连接数据库”,其中,我当时并没有对获取连接的对象进行"两个proxool的连接类进行分别连接数据库"单列模式",所以,我只要调用连接都会重新得到一个连接对象,并重新注册一个连接!
于是,我按照上面的解决思路,解决了问题!