JDBC tomcat连接池无法正常工作

时间:2014-07-19 19:30:39

标签: java jsp tomcat servlets netbeans

Apache tomcat log

  

2014年7月19日下午9:31:31 org.apache.catalina.core.StandardWrapperValve   在for中为servlet [FrontController]调用SEVERE:Servlet.service()   路径[/ GroupFound]的上下文引发了异常   java.lang.ClassCastException:   org.apache.tomcat.dbcp.dbcp.BasicDataSource无法强制转换为   org.apache.tomcat.jdbc.pool.DataSource at   models.bean.Customer.act(Customer.java:32)at   controller.FrontController.processRequest(FrontController.java:40)at   controller.FrontController.doGet(FrontController.java:61)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:621)at at   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:565)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:307)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.runTask(ThreadPoolExecutor.java:886)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:908)     在java.lang.Thread.run(Thread.java:662)

错误

  

org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法创建JDBC   上课的司机''用于连接网址' null'在   org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)     在   org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)     在   org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)     在models.bean.Customer.act(Customer.java:33)at   controller.FrontController.processRequest(FrontController.java:40)at   controller.FrontController.doGet(FrontController.java:61)at   javax.servlet.http.HttpServlet.service(HttpServlet.java:621)at at   javax.servlet.http.HttpServlet.service(HttpServlet.java:722)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:565)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:307)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.runTask(ThreadPoolExecutor.java:886)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:908)     在java.lang.Thread.run(Thread.java:662)引起:   java.lang.NullPointerException at   sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)at   sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)at at   sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)at at   java.sql.DriverManager.getDriver(DriverManager.java:253)at   org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)     ......还有26个

context.xml中 从META-INF文件夹更改。更改META-INF副本时,catalina-home / conf / Catalina / localhost / [projectname] .xml也已更改。

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/GroupFound">
    <Resource auth="Container" 
              defaultReadOnly="false" 
              driverClassName="com.mysql.jdbc.jdbc2.optional" 
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
              initialSize="0" 
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer" 
              jmxEnabled="true" 
              logAbandoned="true" 
              maxActive="300" maxIdle="50"
              maxWait="10000" 
              minEvictableIdleTimeMillis="300000"
              minIdle="30" 
              name="jdbc/testcp"
              password="" 
              removeAbandoned="true"
              removeAbandonedTimeout="60" 
              testOnBorrow="true"
              testOnReturn="false" 
              testWhileIdle="true" 
              timeBetweenEvictionRunsMillis="30000"
              type="javax.sql.DataSource" 
              url="jdbc:mysql://localhost:3306/test" 
              username="root"
              validationInterval="30000" 
              validationQuery="SELECT 1"/>
</Context>

Web.xml中 从应用程序上下文(netbeans IDE)更改

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>FrontController</servlet-name>
        <servlet-class>controller.FrontController</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>FrontController</servlet-name>
        <url-pattern>/index</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

    <resource-ref>
        <description>DB Connection</description>
        <res-ref-name>/jdbc/testcp</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

一直在尝试修复它。搜索谷歌和类似的问题没有成功。我累死。怎么解决?我只是想看看DataSource的工作原理。

详情 JDK 6.1 netbeans 7.2 tomcat 7.0.27

1 个答案:

答案 0 :(得分:0)

这似乎是我能找到的最佳指南:

http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

快速测试就是把它放在这里:

$ CATALINA_BASE / CONF / context.xml中