写了一个简单程序,使用的是SSH框架+Mysql数据库
在同一台计算机上(WindowsXP)使用时,连接是没有问题的,一切均正常
代码和数据库不是同一台计算机上,但系统都是WindowsXP时,连接也是没有问题的,一切正常问题出现在数据库放在Linux上时,一开始是没有问题的,正常访问,但一段时间之后 (大概十几分钟)连接就自动关闭了,程序报错,重启Tomcat后,又可以支撑一会儿,我实在是想不出怎么办了,大家帮帮忙错误信息如下:Last packet sent to the server was 32 ms ago.
2010-05-27 17:40:05  JDBC rollback failed
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:981)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)我的Spring配置文件如下 :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="basedao" class="com.base.BaseDao">
   <property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="com" class="com.base.Common">
   <property name="ibase" ref="basedao"></property>
</bean>

<!-- Dao -->
<bean id="msgdao" class="com.dao.MessageDao">
  <property name="ibase" ref="basedao"></property>
</bean>
<bean id="userinfodao" class="com.dao.UserinfoDao">
   <property name="ibase" ref="basedao"></property>
</bean>


<!-- Service -->
<bean id="msgservice" class="com.service.MessageService">
   <property name="msgdao" ref="msgdao"></property>
   <property name="com" ref="com"></property>
</bean>
<bean id="userinfoservice" class="com.service.UserinfoService">
   <property name="com" ref="com"></property>
   <property name="uidao" ref="userinfodao"></property>
</bean>

<!-- Action -->
<bean name="/message" class="com.struts.action.MessageAction">
   <property name="msgservice" ref="msgservice"></property>
   <property name="com" ref="com"></property>
</bean>
<bean name="/userinfo" class="com.struts.action.UserinfoAction">
   <property name="comm" ref="com"></property>
   <property name="uiservice" ref="userinfoservice"></property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 事务属性 -->
<tx:advice id="mytx">
   <tx:attributes>
       <tx:method name="load*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="select*" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="false" />
   </tx:attributes>
</tx:advice>

<!-- 织入 -->
<aop:config>
   <aop:advisor advice-ref="mytx" pointcut="execution (* com.*.*.*(..))"/>
</aop:config>
</beans>各位一定要帮一下忙啊,我自己弄了几天了,再不出来我估计要……

解决方案 »

  1.   

    是不是你linux 系统有相关设置啊?查查看
      

  2.   

    应该是Linux服务器的问题, 很多软件在xp上是可以支持的,到Linux上是不支持的
      

  3.   

    问题解决了,我用的是Hibernate,在Hibernate配置文件里加上 <!-- C3P0连接池设定--> <property name="hibernate.connection.provider_class">
    org.hibernate.connection.C3P0ConnectionProvider
    </property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.timeout">120</property>
    <property name="hibernate.c3p0.max_statements">100</property>
    <property name="hibernate.c3p0.idle_test_period">120</property>
    <property name="hibernate.c3p0.acquire_increment">2</property>前提是得下载相关Jar包c3p0.jar