自己写的一个数据库连接池的使用

1.在工程里面加入以下jar文件:

    mydatasource.jar,--

     dom4j.jar,

     ojdbc

 2.把连接池配置文件放在工程src目录下或者其他目录,如pool.xml,其内容如下:

 


       
          
                oracle.jdbc.driver.OracleDriver
          

           jdbc:oracle:thin:@192.168.1.7:1521:TESTDB
          appuser
          111111
           1
      

      
          
              oracle.jdbc.driver.OracleDriver
         

         jdbc:oracle:thin:@192.168.1.151:1521:myDB
        admin
        admin
       1
       

 

3。测试类

import java.sql.ResultSet;
import java.sql.Statement;

import org.sky.datasource.ConnectionPoolFactory;
import org.sky.datasource.IConnection;
import org.sky.datasource.IConnectionPool;


public class DsTest
{

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        String conf = "/pool.xml";
        try
        {
            IConnectionPool pool = ConnectionPoolFactory.buildConnectionPoolFactory(conf).getConnectionPool("default");
            IConnection conn = pool.getConnection();
            Statement st = conn.createStatement();
            ResultSet rs = st.executeQuery("select *  from TB_EVENTS");
            while(rs.next()){
                System.out.println(rs.getString(1));
            }
            conn.close();
            //pool.realseConnection(conn);
                   }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
    }

}

 

你可能感兴趣的:(数据库连接池,exception,oracle,string,encoding,events,oracle,j2ee)