Tomcat5.5连接池的配置

 

Tomcat 5.5tomcat5.0的配置是不一样的,Tomcat5.5的配置如下:

server.xml文件中配置如下:

<Context path="/Recommend" reloadable="true" docBase="C:\eclipse\workspace\Recommend" workDir="C:\eclipse\workspace\Recommend\work">

    <Resource name="jdbc/myoracle" auth="Container" type="javax.sql.DataSource"

               maxActive="100" maxIdle="30" maxWait="10000"

username="spstest" password="sps0922"

driverClassName="oracle.jdbc.driver.OracleDriver"

               url="jdbc:oracle:thin:@192.168.6.15:1521:ora9"/>

</Context>

C:\Tomcat 5.5\common\lib目录下拷入class12.jar

class12.jaroraclejdbc的驱动程序不包

 

web.xml中修改代码

<description>oralceDB</description>

<resource-ref>

<description>DB Connection</description>

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

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

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

</resource-ref>

 

测试代码

  <%@ page import="javax.naming.Context" %>

<%@ page import="javax.sql.DataSource"%>

<%@ page import="javax.naming.InitialContext"%>

<%@ page import="java.sql.*"%>

  <%

    DataSource ds = null;

     Context jndiCntx = new InitialContext();

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

          

    if(ds!=null){

      System.out.println("Connection is OK!");

      }

    else

    {

    System.out.println("Connection is fail!");   

    }

   

    Connection cn=ds.getConnection();

    if(cn!=null){

     System.out.println("cn is Ok!");

     }

     else

     {

      System.out.println("cn is fail!");    

     }   

    

    // Statement stmt = cn.createStatement();

    // ResultSet rst = stmt.executeQuery("select * from BOOK");

   //  out.println("<p>rst is Ok!" + rst.next());

   //  while(rst.next()){

   //     System.out.println("<P>BOOK_CODE:" + rst.getString(1));

   //  }    

    cn.close();

 

%>

你可能感兴趣的:(tomcat)