c3p0.max_statements不设置等于0时报如下错误
-
INFO 2010-07-23 16:29:38,490 [com.mchange.v2.c3p0.stmt.GooGooStatementCache] - Problem with checked-in Statement, discarding.
-
java.lang.NullPointerException
##
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size">5</property>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout">120</property>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements">0</property>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period">120</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">2</property>
<!-- 每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate">true</property>
==========================================
“SEVERE: The last packet successfully received from the server was144382 seconds ago.The last packet sent successfully to the server was 144382 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.”
你的log里说的很清楚了。原因是Mysql服务器默认的“wait_timeout”是8小时,如果一个connection空闲超过8个小时,Mysql将自动断开该 connection,而C3P0并不知道该connection已经失效,如果这时请求connection,将会造成上面的异常。你每次使用前判断connection是否有效就会避免这种异常。
解决的方法有3种:
增加wait_timeout的时间。
减少Connection pools中connection的lifetime。
测试Connection pools中connection的有效性。
当然最好的办法是同时综合使用上述3种方法,下面举个例子,假设wait_timeout为默认的8小时
C3P0增加以下配置信息:
//获取connnection时测试是否有效
testConnectionOnCheckin = true
//自动测试的table名称
automaticTestTable=C3P0TestTable
//set to something much less than wait_timeout, prevents connections from going stale
idleConnectionTestPeriod = 18000
//set to something slightly less than wait_timeout, preventing 'stale' connections from being handed out
maxIdleTime = 25000
//if you can take the performance 'hit', set to "true"
testConnectionOnCheckout = true
===================================
1、org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed.
问题:hibernate3默认的lazy为true,使用代理模式proxy属性允许延迟加载类的持久化实例。调用session.load()方法,Hibernate开始会返回CGLIB代理,除主键外的其他值均为null。当代理的某个方法被实际调用的时候, 真实的持久化对象才会被装载,但必须在同一个session中。如session.close()前一直未调用方法,close()后再调用,报上述错误。
解决:a.hbm.xml中 class项,加上lazy=false
b.使用session.get()方法,将不延迟,直接取出对象实例。
2、java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
问题:ms SQLserver在设置为autoCommit=false,SelectMethod=direct时,处理多个statement将报该错
解决:在url加上设置SelectMethod=Cursor
3、java.lang.NullPointerException: Problem with checked-in Statement, discarding.
问题:oracle9i前的jdbc Driver有bug,多个statement亦会出错
解决:在http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html上下载最新的ojdbc14.jar,版本为10.2.0.1.0
|
分享到:
相关推荐
hibernate c3p0 数据库 连接池 参数 详解
Default password for ifx_connect() (doesn't apply in safe mode). ifx.default_password = ; Allow or prevent persistent links. ifx.allow_persistent = On ; Maximum number of persistent links. -1 means...
They can be turned off using the values 0, Off, False or No. ; An empty string can be denoted by simply not writing anything after the equal ; sign, or by using the None keyword: ; foo = ; sets foo...
解决Eclipse中使用drool时报Caused by: java.lang.RuntimeException: The Eclipse JDT Core jar is not in the classpath的问题。 详细错误: org.drools.RuntimeDroolsException: Unable to load dialect 'org....
SELECT TOP 100 usecounts, objtype, p.size_in_bytes,[sql].[text] FROM sys.dm_exec_cached_plans p OUTER APPLY sys.dm_exec_sql_text (p.plan_handle) sql ORDER BY usecounts,p.size_in_bytes desc ...
复制到 pgsql-12/lib 目录下就可以了 然后修改 postgresql.conf shared_preload_libraries = 'timescaledb, pg_stat_statements...pg_stat_statements.max = 10000 pg_stat_statements.track = all 最后重启postgrelSQL
This program written in matlab (.m) or matlab code is good example of switch-case statements. IF STATEMENT- The switch statement permits us to different statements based on the different values of a ...
Conditions in if-statements. conditions.py Else-if (elif) statements. elif_statements.py Strings and numbers. strings_and_numbers.py Chapter 6 Five Hellos. five_hellos.py Huge hairy pants (example 1)...
《MySQL开发者SQL权威指南》的例子代码
pg_log_statements pg_log_statements是一个PostgreSQL扩展,它允许记录特定数据库会话SQL语句:可以为特定服务器进程设置log_statement ,而不是在实例级别或数据库级别设置log_statement参数。安装编译中可以使用...
VB编程设计财务报表模块代码VB Programming module code of financial statements
2.SQL Data Statements--those used to create, manipulate, and retrieve data stored in your database example statements include select, update, insert, and delete 3.SQL Schema Statements--those used to ...
#hibernate.c3p0.max_statements 100 #hibernate.c3p0.idle_test_period 3000 #hibernate.c3p0.acquire_increment 2 #hibernate.c3p0.validate false ############################## ### Proxool Connection ...
Encoder Using Assign Statements: Unlike a multiplexer that selects one individual data input line and then sends that data to a single output line or switch, an Encoder takes all the data inputs one ...
下列语句部分是MsSql语句,不可以在access中使用。 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRANT,REVOKE,COMMIT...
BIG DATA research papers
An object that registers to be notified of events that occur on PreparedStatements that are in the Statement pool.
Bug with using the datetime literals in SQL statements in TVirtualQuery is fixed Bug with AV failure in the Refresh method in RAD Studio 10.2 Tokyo on Linux is fixed Oracle data provider Bug with ...
-- interfering with SELECT statements. SET NOCOUNT ON; CREATE TABLE [dbo].[ReDealCheck]( [AppplyNo] [varchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL, [FileType] [varchar](2) COLLATE Chinese_PRC_...
checked and unchecked Statements 274 Summary 277 12 Event-Based Programming with Delegates and Events 278 Exposing Delegates 279 Implementing Delegate Inference 285 Assigning Anonymous ...