Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate-Tomcat-MySQL问题_Mysql_Hibernate_Tomcat_Struts_C3p0 - Fatal编程技术网

Hibernate-Tomcat-MySQL问题

Hibernate-Tomcat-MySQL问题,mysql,hibernate,tomcat,struts,c3p0,Mysql,Hibernate,Tomcat,Struts,C3p0,亲爱的大家, 我正在tomcat7上使用hibernate mysql测试Struts Web应用程序 8小时超时后,我的Web应用程序总是崩溃。我在这里和那里改变了配置。但是没有成功 我真的很感谢你的关注 下面是hibernate.xml中的几行代码 property name="hibernate.bytecode.use_reflection_optimizer">false property name="hibernate.c3p0.idle_test_period

亲爱的大家,
我正在tomcat7上使用hibernate mysql测试Struts Web应用程序

8小时超时后,我的Web应用程序总是崩溃。我在这里和那里改变了配置。但是没有成功

我真的很感谢你的关注

下面是hibernate.xml中的几行代码


 property name="hibernate.bytecode.use_reflection_optimizer">false
    property name="hibernate.c3p0.idle_test_period">30
    property name="hibernate.c3p0.max_size">600
    property name="hibernate.c3p0.max_statements">50
    property name="hibernate.c3p0.min_size">5
    property name="hibernate.c3p0.timeout">1800
    property name="hibernate.c3p0.testConnectionOnCheckout">true
    property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
    property name="hibernate.c3p0.validate">true
    property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver
    property name="hibernate.connection.url">jdbc:mysql://localhost:3306/stockdb?autoReconnect=true


以下是我的stacktraces中的一些行:



请帮忙

包含了开箱即用的内容。要配置,例如:

<Context>

    <!-- maxActive: Maximum number of database connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to -1 for no limit.
         -->

    <!-- maxIdle: Maximum number of idle database connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->

    <!-- maxWait: Maximum time to wait for a database connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->

    <!-- username and password: MySQL username and password for database connections  -->

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->

    <!-- url: The JDBC connection url for connecting to your MySQL database.
         -->

  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/javatest"/>

</Context>

现在,像往常一样处理JDBC代码。

Tomcat已经这样做了,使c3p0变得不必要。太棒了。这对我的知识贫乏来说是全新的。。。。非常感谢您的提示。我将把它作为一个答案,以及一些来自页面的配置细节,所以您可以接受它在一秒钟请。。。你真是太好了…好了,祝你好运,如果你还有什么问题,请告诉我。。。如何结合hibernate和struts。。。这会不会是一场冲突?既然有一个关于这方面的教程,我猜这不会是一场冲突。当然我会投票支持你。。。但我的名声还不够。但我一定会投票的。再一次你好。。。我正在使用tomcat连接池。到目前为止,它运行良好。但有时它会给出SQLException“PooledConnection已经关闭”。你知道为什么会发生这种情况吗?使用XML中的maxActive、maxAllowed和maxWait参数,以及Java代码中指定的时间。希望有帮助。如果你仍然有问题,用你的代码编辑你的问题,我来看看。
<Context>

    <!-- maxActive: Maximum number of database connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to -1 for no limit.
         -->

    <!-- maxIdle: Maximum number of idle database connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->

    <!-- maxWait: Maximum time to wait for a database connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->

    <!-- username and password: MySQL username and password for database connections  -->

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->

    <!-- url: The JDBC connection url for connecting to your MySQL database.
         -->

  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/javatest"/>

</Context>
    public static void main(String[] args) throws Exception {
        PoolProperties p = new PoolProperties();
        p.setUrl("jdbc:mysql://localhost:3306/mysql");
        p.setDriverClassName("com.mysql.jdbc.Driver");
        p.setUsername("root");
        p.setPassword("password");
        p.setJmxEnabled(true);
        p.setTestWhileIdle(false);
        p.setTestOnBorrow(true);
        p.setValidationQuery("SELECT 1");
        p.setTestOnReturn(false);
        p.setValidationInterval(30000);
        p.setTimeBetweenEvictionRunsMillis(30000);
        p.setMaxActive(100);
        p.setInitialSize(10);
        p.setMaxWait(10000);
        p.setRemoveAbandonedTimeout(60);
        p.setMinEvictableIdleTimeMillis(30000);
        p.setMinIdle(10);
        p.setLogAbandoned(true);
        p.setRemoveAbandoned(true);
 p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
        DataSource datasource = new DataSource();
        datasource.setPoolProperties(p); 

        Connection con = null;
        con = datasource.getConnection();