一、resin.conf
     <!--
       - Sample database pool configuration
       -
       - The JDBC name is java:comp/env/jdbc/test
       -
         <database>
           <jndi-name>jdbc/mysql</jndi-name>
           <driver type="org.gjt.mm.mysql.Driver">
             <url>jdbc:mysql://localhost:3306/test</url>
             <user></user>
             <password></password>
            </driver>
            <prepared-statement-cache-size>8</prepared-statement-cache-size>
            <max-connections>20</max-connections>
            <max-idle-time>30s</max-idle-time>
          </database>
      -->
          <database>
           <jndi-name>jdbc/mysql</jndi-name>
           <driver type="org.gjt.mm.mysql.Driver">
             <url>jdbc:mysql://localhost:3306/test</url>
             <user></user>
             <password></password>
            </driver>
            <prepared-statement-cache-size>8</prepared-statement-cache-size>
            <max-connections>20</max-connections>
            <max-idle-time>30s</max-idle-time>
          </database>

解决方案 »

  1.   

    二、你的程序中WEB-INF\web.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
      <servlet>
        <servlet-name>debugjsp</servlet-name>
        <description>Added to compile JSPs with debug info</description>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
          <param-name>classdebuginfo</param-name>
          <param-value>true</param-value>
        </init-param>
        <load-on-startup>3</load-on-startup>
      </servlet>
      <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>jdbc/mysql</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>
    </web-app>
      

  2.   

    测试jsp文件
    <%@ page contentType="text/html;charset=GBK"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="javax.naming.*"%>
    <%@ page import="javax.sql.DataSource"%>
    <%Connection conn=null;
             try {
                Context initCtx = new InitialContext();
                Context ctx = (Context) initCtx.lookup("java:comp/env");
                //获取连接池对象
                Object obj = (Object) ctx.lookup("jdbc/mssql");
                //类型转换
                javax.sql.DataSource ds = (javax.sql.DataSource) obj;
                conn = ds.getConnection();
               out.println("数据库连接正常(连接池)!");
            }
            catch (Exception ex) {
                ex.printStackTrace();
                out.println("数据库无法连接(连接池)!"+ex.getMessage());
                conn = null;
            }
    %>
      

  3.   

    不好意思一resin.conf改成
    一、resin.conf
         <!--
           - Sample database pool configuration
           -
           - The JDBC name is java:comp/env/jdbc/test
           -
             <database>
               <jndi-name>jdbc/mysql</jndi-name>
               <driver type="org.gjt.mm.mysql.Driver">
                 <url>jdbc:mysql://localhost:3306/test</url>
                 <user></user>
                 <password></password>
                </driver>
                <prepared-statement-cache-size>8</prepared-statement-cache-size>
                <max-connections>20</max-connections>
                <max-idle-time>30s</max-idle-time>
              </database>
          -->
              一、resin.conf
         <!--
           - Sample database pool configuration
           -
           - The JDBC name is java:comp/env/jdbc/test
           -
             <database>
               <jndi-name>jdbc/mysql</jndi-name>
               <driver type="org.gjt.mm.mysql.Driver">
                 <url>jdbc:mysql://localhost:3306/test</url>
                 <user></user>
                 <password></password>
                </driver>
                <prepared-statement-cache-size>8</prepared-statement-cache-size>
                <max-connections>20</max-connections>
                <max-idle-time>30s</max-idle-time>
              </database>
          -->
             <database>
               <jndi-name>jdbc/mssql</jndi-name>
               <driver type="com.microsoft.jdbc.sqlserver.SQLServerDriver">
                   <url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wuye</url>
                 <user>sa</user>
                 <password>china</password>
                </driver>
                <max-connections>20</max-connections>
                <max-idle-time>30s</max-idle-time>
              </database>
      

  4.   

    一、resin.conf应该是
         ............
         <!--
           - Sample database pool configuration
           -
           - The JDBC name is java:comp/env/jdbc/test
           -
             <database>
               <jndi-name>jdbc/mysql</jndi-name>
               <driver type="org.gjt.mm.mysql.Driver">
                 <url>jdbc:mysql://localhost:3306/test</url>
                 <user></user>
                 <password></password>
                </driver>
                <prepared-statement-cache-size>8</prepared-statement-cache-size>
                <max-connections>20</max-connections>
                <max-idle-time>30s</max-idle-time>
              </database>
          -->
             <database>
               <jndi-name>jdbc/mssql</jndi-name>
               <driver type="com.microsoft.jdbc.sqlserver.SQLServerDriver">
                   <url>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=wuye</url>
                 <user>sa</user>
                 <password>china</password>
                </driver>
                <max-connections>20</max-connections>
                <max-idle-time>30s</max-idle-time>
              </database>
        .........