为您推荐:
精华内容
最热下载
问答
  • 552B qq_35973977 2018-05-30 10:14:06
  • 1KB qq_38932416 2019-08-15 16:27:52
  • 385KB beauxie 2016-09-22 14:46:43
  • 1.62MB weixin_42131383 2019-06-13 17:00:13
  • 前面的学习我们了解到,想要使用C3P0必须加入c3p0-config.xml 那么C3P0内部是如何运作来获取数据库连接信息的呢? 其实,也是它是通过dom4j+xpath对xml文件进行了解析,从而获取到了想要的属性 这也就明确了为什么c3p...

    前面的学习我们了解到,想要使用C3P0必须加入c3p0-config.xml

    那么C3P0内部是如何运作来获取数据库连接信息的呢?

    其实,也是它是通过dom4j+xpath对xml文件进行了解析,从而获取到了想要的属性

    这也就明确了为什么c3p0-config.xml的名字不能被修改,而且里面的配置格式也不可能调整,因为都是程序内定的!

    下面通过案例来模拟模拟C3P0解析c3p0-config.xml的过程:

    一.案例展示

    1.测试准备

    项目工程

    2.代码展示(这里会将解析出来的信息封装成对象)

    ***pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.howie</groupId>
        <artifactId>parsexml_c3p0</artifactId>
        <version>1.0-SNAPSHOT</version>
        
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
        <dependencies>
            <!--单元测试-->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <!--dom4j-->
            <dependency>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
                <version>1.6.1</version>
            </dependency>
            <!--xpath-->
            <dependency>
                <groupId>jaxen</groupId>
                <artifactId>jaxen</artifactId>
                <version>1.1.6</version>
            </dependency>
        </dependencies>
    </project>

    ***c3p0-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <c3p0-config>
      <default-config>
    	<property name="driverClass">com.mysql.jdbc.Driver</property>
    	<property name="jdbcUrl">jdbc:mysql://localhost:3306/mysqlstudy?characterEncoding=utf8</property>
    	<property name="user">root</property>
    	<property name="password">root</property>
        <property name="initialPoolSize">10</property>
      </default-config>
    </c3p0-config>

    ***XmlConfigBuilder.java

    package com.howie.utils;
    
    import com.howie.pojo.Configuration;
    import org.dom4j.Document;
    import org.dom4j.Element;
    import org.dom4j.io.SAXReader;
    
    import java.io.InputStream;
    import java.util.List;
    
    /**
     * @Author weihuanwen
     * @Date 2019/8/6 10:34
     * @Version 1.0
     */
    public class XmlConfigBuilder {
    
        public static Configuration loadXmlConfig(InputStream is){
            //8.封装Configuration对象
            Configuration config = new Configuration();
            //1.获取SAXReader对象
            SAXReader saxReader = new SAXReader();
            try {
                //2.获取操作xml文件的document对象
                Document document = saxReader.read(is);
                //3.获取根节点对象
                Element rootElement = document.getRootElement();
                //4.通过xPath语法找到所有的property标签
                List<Element> properties = rootElement.selectNodes("//property");
                //5.非空判断
                if (properties != null && properties.size() > 0){
                    //6.遍历proerty标签
                    for (Element property : properties) {
                        //7.获取标签的属性
                        String name = property.attributeValue("name");
                        String value = property.getText();
                        //9.匹配字段并为对象赋值
                        if ("driverClass".equals(name)){
                            config.setDriverClass(value);
                        }
                        if ("jdbcUrl".equals(name)){
                            config.setJdbcUrl(value);
                        }
                        if ("user".equals(name)){
                            config.setUser(value);
                        }
                        if ("password".equals(name)){
                            config.setPassword(value);
                        }
                        if ("initialPoolSize".equals(name)){
                            config.setInitialPoolSize(Integer.parseInt(value));
                        }
                    }
                }
                //关闭输入流
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return config;
        }
    }
    

    ***Configuration.java

    package com.howie.pojo;
    
    /**
     * @Author weihuanwen
     * @Date 2019/8/6 10:32
     * @Version 1.0
     */
    public class Configuration {
        private String driverClass;
        private String jdbcUrl;
        private String user;
        private String password;
        private Integer initialPoolSize;
    
        public String getDriverClass() {
            return driverClass;
        }
    
        public void setDriverClass(String driverClass) {
            this.driverClass = driverClass;
        }
    
        public String getJdbcUrl() {
            return jdbcUrl;
        }
    
        public void setJdbcUrl(String jdbcUrl) {
            this.jdbcUrl = jdbcUrl;
        }
    
        public String getUser() {
            return user;
        }
    
        public void setUser(String user) {
            this.user = user;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public Integer getInitialPoolSize() {
            return initialPoolSize;
        }
    
        public void setInitialPoolSize(Integer initialPoolSize) {
            this.initialPoolSize = initialPoolSize;
        }
    
        @Override
        public String toString() {
            return "Configuration{" +
                    "driverClass='" + driverClass + '\'' +
                    ", jdbcUrl='" + jdbcUrl + '\'' +
                    ", user='" + user + '\'' +
                    ", password='" + password + '\'' +
                    ", initialPoolSize=" + initialPoolSize +
                    '}';
        }
    }
    

    ***SimulatedParseXml.java

    package com.howie.textparsing;
    
    import com.howie.pojo.Configuration;
    import com.howie.utils.XmlConfigBuilder;
    import org.junit.Test;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.InputStream;
    
    /**
     * @Author weihuanwen
     * @Date 2019/8/6 10:30
     * @Version 1.0
     */
    public class SimulatedParseXml {
    
        @Test
        public void getDetail() throws FileNotFoundException {
            String path = "src/main/resources/c3p0-config.xml";
            InputStream is = new FileInputStream(path);
            Configuration config = XmlConfigBuilder.loadXmlConfig(is);
            System.out.println(config);
        }
    }
    

    3.测试

    ①执行SimulatedParseXml的getDetail()

    ②控制台输出:

    Configuration{driverClass='com.mysql.jdbc.Driver', jdbcUrl='jdbc:mysql://localhost:3306/mysqlstudy?characterEncoding=utf8', user='root', password='root', initialPoolSize=10}

    二.总结

    1.DOM4j

    ①是一个易用的、开源的库,用于XML,XPath和XSLT

    ②通过其可以获取所有的结点

    ③支持XPath

    2.Xpah

    ①一种用来确定XML文档中某部分位置的语言

    ②其相关表达式如下:

    表达式

    描述

    nodename

    选取此节点的所有子节点。

    /

    从根节点选取。

    //

    从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置。

    .

    选取当前节点。

    ..

    选取当前节点的父节点。

    ③路径表达式以及表达式的结果:

    路径表达式

    结果

    bookstore

    选取 bookstore 元素的所有子节点。

    /bookstore

    选取根元素 bookstore。

    注释:假如路径起始于正斜杠( / ),则此路径始终代表到某元素的绝对路径!

    bookstore/book

    选取属于 bookstore 的子元素的所有 book 元素。

    //book

    选取所有 book 子元素,而不管它们在文档中的位置。

    bookstore//book

    选择属于 bookstore 元素的后代的所有 book 元素,而不管它们位于 bookstore 之下的什么位置。

    //@lang

    选取名为 lang 的所有属性。

    展开全文
    FloatDreamed 2019-08-06 11:42:53
  • 配置环境: c3p0-0.9.5.2.jar c3p0-0.9.5.2-sources.jar hamcrest-core-1.3.jar javax.servlet-api-3.1.0.jar ...编写c3p0-config.xml文件 <?xml version="1.0" encoding="utf-8" ?> <c3p0-c

    配置环境:
    c3p0-0.9.5.2.jar
    c3p0-0.9.5.2-sources.jar
    hamcrest-core-1.3.jar
    javax.servlet-api-3.1.0.jar
    junit-4.12.jar
    mchange-commons-java-0.2.11.jar
    mysql-connector-java-5.1.7-bin.jar

    编写c3p0-config.xml文件

    <?xml version="1.0" encoding="utf-8" ?>
    <c3p0-config>
        <default-config>
            <!--数据库的连接账号(账号基本上都是root)-->
            <property name="user">root</property>
            <!--数据库的连接密码-->
            <property name="password">root</property>
            <!--获取数据库连接(newsmanagersystem)是数据库的名称-->
            <property name="jdbcUrl">jdbc:mysql://localhost:3306/newsmanagersystem</property>
            <!--连接MySQL数据库的配置文件 注:等号前后不要有空格-->
            <!--驱动名-->
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <!--连接池初始化的时候连接数-->
            <property name="initialPoolSize">10</property>
            <!--连接池中连接的最大个数-->
            <property name="maxPoolSize">100</property>
            <!--用户获得Connection的时候,如果有连接就获得,没有就等待时间,如果超时就报异常-->
            <property name="maxIdleTime">30</property>
            <!--连接池中连接的最小个数-->
            <property name="minPoolSize">10</property>
        </default-config>
    </c3p0-config>
    

    编写com.xxx.utils并创建C3p0Utils类

    package com.xxx.utils;
    
    import com.mchange.v2.c3p0.ComboPooledDataSource;
    import javax.sql.DataSource;
    import java.sql.Connection;
    import java.sql.SQLException;
    
    public class C3p0Utils {
    
        //得到dataSource
        private static DataSource dataSource=new ComboPooledDataSource();
    
        //获取数据库连接
        public static Connection getConnection(){
            try {
                return dataSource.getConnection();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    
        //返回dataSource
        public static DataSource getDataSource(){
            return dataSource;
        }
    }
    

    编写com.xxx.test包在其下创建c3p0Test类,用于测试c3p0-config.xml是否连接到数据源

    package com.xxx.test;
    
    import com.bojian.utils.C3p0Utils;
    import org.junit.Test;
    import java.sql.SQLException;
    
    public class C3p0Test {
        /**
         * 单元测试方法
         * 1.方法的返回值,建议使用void,一般没有返回值
         * 2.参数列表,建议空参,一般是没有参数
         * 3.方法上需要书写上@Test注解
         * 4.每个方法都能独立运行
         *
         * 判断结果 你好 魏昭星
         * 判断结果 你好 魏昭星
         *  绿色:成功
         *  红色:失败
         */
        @Test
        public void TestC3p0Utils(){
            System.out.println(C3p0Utils.getConnection());
            try {
                C3p0Utils.getConnection().close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    

    控制台报错

    • c3p0-config.xml的首字母大写
    • c3p0-config.xml的配置不规范
    • 需要的环境没配置好
    展开全文
    juedaifenghua2 2021-04-15 00:41:41
  • c3p0-config.xml文件模板com.mysql.cj.jdbc.Driverjdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTCroot1234520java测试文件需要导入【c3p0-0.9.2-pre1.jar】与【mysql-connector-java-8.0.19...

    c3p0-config.xml文件模板

    com.mysql.cj.jdbc.Driver

    jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC

    root

    1234

    5

    20

    java测试文件

    需要导入【c3p0-0.9.2-pre1.jar】与【mysql-connector-java-8.0.19.jar】

    如有需要可以私信;

    import java.sql.Connection;

    import java.sql.SQLException;

    import org.junit.Test;

    import cn.itcast.jdbc.JdbcUtils;

    public class JdbcUtilsTest {

    @Test

    public void testGetConnection()throws SQLException{

    Connection con=JdbcUtils.getConnection();

    System.out.println(con);

    JdbcUtils.releaseConnection(con);

    System.out.println(con.isClosed());

    }

    }测试成功!

    展开全文
    weixin_29311017 2021-01-18 22:19:22
  •  at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)  at ...

    1.当时进行JavaWeb开发中,遇到了以下问题,百度的很多的博客,都没有解决。页面出现的错误提示:

    控制台出现的错误提示的所有信息如下:

    四月 24, 2019 8:00:44 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
    警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1b642923 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
    java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(Unknown Source)
        at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

    四月 24, 2019 8:00:44 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
    警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@54447ef9 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
    java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(Unknown Source)
        at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

    四月 24, 2019 8:00:44 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
    警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@2bc88eb0 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
    java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(Unknown Source)
        at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:119)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:143)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:132)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
        at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

    java.sql.SQLException: Connections could not be acquired from the underlying database!
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
        at org.apache.commons.dbutils.AbstractQueryRunner.prepareConnection(AbstractQueryRunner.java:156)
        at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:453)
        at com.imooc.dao.impl.UserDaoImpl.regist(UserDaoImpl.java:22)
        at com.imooc.service.impl.UserServiceImpl.regist(UserServiceImpl.java:17)
        at com.imooc.web.servlet.RegistServlet.doGet(RegistServlet.java:42)
        at com.imooc.web.servlet.RegistServlet.doPost(RegistServlet.java:52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)
    Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
        ... 29 more
    java.sql.SQLException: Connections could not be acquired from the underlying database!
        at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
        at org.apache.commons.dbutils.AbstractQueryRunner.prepareConnection(AbstractQueryRunner.java:156)
        at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:453)
        at com.imooc.dao.impl.UserDaoImpl.regist(UserDaoImpl.java:22)
        at com.imooc.service.impl.UserServiceImpl.regist(UserServiceImpl.java:17)
        at com.imooc.web.servlet.RegistServlet.doGet(RegistServlet.java:42)
        at com.imooc.web.servlet.RegistServlet.doPost(RegistServlet.java:52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    四月 24, 2019 8:00:44 下午 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet [RegistServlet] in context with path [/regist_web] threw exception
    java.lang.RuntimeException
        at com.imooc.web.servlet.RegistServlet.doGet(RegistServlet.java:46)
        at com.imooc.web.servlet.RegistServlet.doPost(RegistServlet.java:52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)

        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)
    Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
        ... 29 more
    四月 24, 2019 8:00:44 下午 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet [RegistServlet] in context with path [/regist_web] threw exception
    java.lang.RuntimeException
        at com.imooc.web.servlet.RegistServlet.doGet(RegistServlet.java:46)
        at com.imooc.web.servlet.RegistServlet.doPost(RegistServlet.java:52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Unknown Source)

    2.后来发现,原来一开始c3p0-config.xml文件就有一些问题。于是就做新弄了一下c3p0-config.xml的内容。

    下面是后来可以正常运行的c3p0-config.xml文件的代码内容:

    <?xml version="1.0" encoding="UTF-8"?>
    <c3p0-config>
        <default-config>
            <property name="jdbcUrl">jdbc:mysql://localhost:3306/regist_web
            </property>
            <property name="driverClass">com.mysql.jdbc.Driver</property>
            <property name="user">root</property>
            <property name="password">123456</property> 
            <property name="checkoutTimeout">30000</property>
            <property name="idleConnectionTestPeriod">30</property>
            <property name="initialPoolSize">10</property>
            <property name="maxIdleTime">30</property>
            <property name="maxPoolSize">100</property>
            <property name="minPoolSize">10</property>
            <property name="maxStatements">200</property>
        </default-config>
    </c3p0-config>

    3.总结:由于第一次使用c3p0-config.xml配置文件,所以有很多深层的东西不是很清楚,才会导致这样的状况出现。于是记下来,给自己提个醒。

     

    展开全文
    JontyXu 2019-04-24 20:18:47
  • weixin_46186045 2021-02-24 22:19:19
  • gaotao3037 2021-01-10 01:11:22
  • qq_39740279 2019-08-19 09:54:56
  • qq_45920729 2020-04-01 22:35:21
  • qq_41901915 2019-01-15 15:22:06
  • caychen 2018-03-20 14:40:13
  • weixin_44893467 2019-08-14 18:09:42
  • m0_46491185 2020-05-07 14:06:22
  • weixin_33273250 2021-03-19 10:08:12

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 38,386
精华内容 15,354
关键字:

c3p0-config.xml