tomcat里的数据池配置是否正确?你的代码怎么写的?

解决方案 »

  1.   

    <Server port="8005" shutdown="SHUTDOWN" debug="0">
      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
                debug="0"/>
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
                debug="0"/>  <GlobalNamingResources>    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>    <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
           description="User database that can be updated and saved">
        </Resource>
        <ResourceParams name="UserDatabase">
          <parameter>
            <name>factory</name>
            <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
          </parameter>
          <parameter>
            <name>pathname</name>
            <value>conf/tomcat-users.xml</value>
          </parameter>
        </ResourceParams>  </GlobalNamingResources>  <Service name="Catalina">
        <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   debug="0" connectionTimeout="20000" 
                   disableUploadTimeout="true" />    <Connector port="8009" 
                   enableLookups="false" redirectPort="8443" debug="0"
                   protocol="AJP/1.3" />
        <Engine name="Catalina" defaultHost="localhost" debug="0">      <Logger className="org.apache.catalina.logger.FileLogger"
                  prefix="catalina_log." suffix=".txt"
                  timestamp="true"/>      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                     debug="0" resourceName="UserDatabase"/>
          <Host name="localhost" debug="0" appBase="webapps"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="false" xmlNamespaceAware="false">      
          <Logger className="org.apache.catalina.logger.FileLogger"
                     directory="logs"  prefix="localhost_log." suffix=".txt"
                timestamp="true"/>
    <Context path="" docBase="ROOT"  debug="0" reloadable="true" crossContext="true">
     <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"/>
      <ResourceParams name="jdbc/TestDB">
       <parameter>
         <name>factory</name>
         <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
       </parameter>
       <parameter>
         <name>driverClassName</name>
         <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
       </parameter>
       <parameter>
         <name>url</name>
         <value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev</value>
       </parameter>
       <parameter>
        <name>username</name>
        <value>sa</value>
       </parameter>
       <parameter>
        <name>password</name>
        <value>abc</value>
       </parameter>
       <parameter>
         <name>maxActive</name>
         <value>100</value>
       </parameter>
       <parameter>
         <name>maxIdle</name>
         <value>30</value>
       </parameter>
       <parameter>
         <name>maxWait</name>
         <value>80</value>
       </parameter>
     </ResourceParams>
     </Context>
          </Host>    </Engine>  </Service></Server>
      

  2.   

    我是将<context>...</context>加在</host>前
      

  3.   

    这是我的测试jsp程序
    <%@ page contentType="text/html; charset=GBK"%>
    <%@ page import="java.sql.*,    javax.naming.*"%>
    <% 
    try {
        Context initCtx = new InitialContext();
        Context ctx = (Context) initCtx.lookup("java:comp/env");
        Object obj = (Object) ctx.lookup("jdbc/TestDB"); 
        javax.sql.DataSource ds = (javax.sql.DataSource)obj;
        Connection conn = ds.getConnection();
        Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
            java.sql.ResultSet.CONCUR_READ_ONLY);
        String strSQL = "SELECT * FROM test"; 
        ResultSet rs = stmt.executeQuery(strSQL);
    %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    ...
    </html> 
    <% 
        rs.close(); 
        stmt.close(); 
        conn.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    %>
      

  4.   

    MS SQL我也在安全性-登录里把默认用户sa的密码设成了abc
      

  5.   

    上面有一句写错了,应该是String strSQL = "SELECT * FROM jspdev";
      

  6.   

    我是连接mysql有问题……
    挨!
      

  7.   

    代码写的没有问题。
    在应用的 web.xml 文件中是否添加如下 DataSource 声名:
    <resource-ref>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>
      

  8.   

    I get this error using Tomcat 5.0.18 under Debian/Linux. Using the same 
    configuration under Windows XP, there is no problem. Using the same 
    application under Tomcat 4.1.27, there is no problem (either Linux or 
    Windows). 
    As you can see from the included stack trace, I am using Hibernate which 
    is accessing the configured DataSource in a Servlet Filter at 
    application startup. 
    I have searched for this problem on this Mailing List, but got no clue. 
    I am using a Context local DataSource (no Global), and have everything 
    strictly setup as described in the JNDI HowTo. Given the number of 
    people that could not solve the problem, maybe there is a bug in Tomcat5?