- package aa;
- import java.io.File;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- import org.apache.log4j.PropertyConfigurator;
- import org.logicalcobwebs.proxool.ProxoolException;
- import org.logicalcobwebs.proxool.ProxoolFacade;
- import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
- import bsh.This;
- public class Test {
- /**
- * <xmp>
- *
- * </xmp>
- *
- * @param args
- * @author 金鑫 2010-9-27 下午04:45:29
- * @throws SQLException
- * @throws ProxoolException
- * @throws InterruptedException
- */
- public static void main(String[] args) throws SQLException, ProxoolException, InterruptedException {
- // TODO Auto-generated method stub
- readXmlFile("aa/aa.xml");
- readXmlFile("aa/bb.xml");
- Connection conn1 = getConnection("aa");
- Statement sta1 = conn1.createStatement();
- System.out.println(conn1);
- sta1.executeQuery("select * from wcmuser");
- Connection conn2 = getConnection("bb");
- System.out.println(conn2);
- Statement sta2 = conn2.createStatement();
- sta2.executeQuery("select * from idsuser");
- int k =0 ;
- while(k<2){
- Thread.sleep(10000);
- k++;
- }
- conn1.close();
- conn2.close();
- while(k<4){
- Thread.sleep(10000);
- k++;
- }
- ProxoolFacade.removeConnectionPool("aa");//动态删除
- }
- public static Connection getConnection(String sessionID) {
- try {
- Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
- return DriverManager.getConnection("proxool."+sessionID);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- return null;
- }
- public static void readXmlFile(String xmlurl) {
- String appDir = Thread.currentThread().getContextClassLoader()
- .getResource("").toString();
- appDir = appDir.substring(6, appDir.length());
- Properties properties = new Properties();
- File file;
- try {
- file = new File(xmlurl);
- if (file.isAbsolute())
- JAXPConfigurator.configure(xmlurl, false);
- else
- JAXPConfigurator.configure(appDir + File.separator + xmlurl,
- false);
- } catch (ProxoolException e) {
- e.printStackTrace();
- }
- if (properties.size() > 0) {
- PropertyConfigurator.configure(properties);
- }
- }
- }
proxool 多数据源动态切换
最新推荐文章于 2021-02-28 23:41:19 发布