tomcat下连接池的配置

来源:互联网 发布:java笔记 编辑:程序博客网 时间:2024/04/28 19:44

1.把数据库JDBC驱动拷贝到

 %TOMCAT_HOME%/common/lib

 或

 %TOMCAT_HOME%/webapps/yourweb/WEB-INF/lib 下;


2.配置 conf/context.xml ,加入如下信息:

  <Resource name="jdbc/myoracle"

            auth="Container"

            type="javax.sql.DataSource"

            driverClassName="oracle.jdbc.OracleDriver"

            url="jdbc:oracle:thin:@127.0.0.1:1521:mysid"

            username="scott"

            password="tiger"

            maxActive="20"

            maxIdle="10"

            maxWait="1000"  />


3.配置 web.xml

  <resource-ref>

    <description>Oracle Datasource example</description>

    <res-ref-name>jdbc/myoracle</res-ref-name>

    <res-type>javax.sql.DataSource</res-type>

    <res-auth>Container</res-auth>

  </resource-ref>


3.java 查找池的 jndi 代码:

   Context initContext = new InitialContext();

   DataSource ds = (Context)initContext.lookup("java:/comp/env/ jdbc/myoracle ");

   Connection conn = ds.getConnection();


原创粉丝点击