id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	due_date
136	关于启用preparestatment cache的问题	yuanhuoqing		"    之前产品库遇到个问题，oracle数据表表增加个字段后会报数据库异常：Cause: java.sql.SQLException: 违反协议
  然后导致数据库查询很慢，时间久了点会导致数据库游标超限等异常。对应的应用代码可以不更新，只要应用重启后问题就可以解决，在应用重启的过程中会影响网友访问10来分钟。网上找到一个相同的案例：http://www.iteye.com/topic/900077 ，这个报错跟启用preparestatment cache有关。
    经过在测试环境测试分析，发现是我们的数据源配置启用了preparestatment cache，配置如下：
{{{
<database jndi-name=""jdbc/product"">
      <driver user=""product"" password=""product"" url=""jdbc:oracle:thin:@192.168.75.100:1521:testdb"" type=""oracle.jdbc.driver.OracleDriver""/>
	<prepared-statement-cache-size>8</prepared-statement-cache-size>
	<max-connections>20</max-connections>
	<max-idle-time>30s</max-idle-time>
</database>
}}}
     参数<prepared-statement-cache-size>8</prepared-statement-cache-size>即是启用preparestatment cache，默认是不启用的，即这个值为0。
    PreparedStatement是JDBC里面提供的对象，很多连接池都引入了PreparedStatementCache的概念。如Jboss连接池、C3P0,DBCP等。PreparedStatementCache即用于保存与数据库交互的prepareStatement对象。在cache里的ps对象，不需要重新走一次DBMS连接请求去创建。 
    PreparedStatementCache是跟着connection走的。一个connection就会有一个cache。比如一个cache允许缓存20条语句，20个connection就可能缓存400个。一般连接池可以支持这个的配置，能提高性能，但会占用较大内存，同时增加表字段时如果不重启应用会报异常：java.sql.SQLException: 违反协议，需要重启应用才能解决，所以慎用PreparedStatementCache。"	总结	new	major	2012报价库5.0	报价库	报价库5.0		preparestatment cache		18/02/2013
