无法检查jdbc自动提交模式,连接已关闭错误

k2arahey  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(392)

在尝试连接到外部 Sybase db,我得到下面的跟踪。但是,当我重新启动连接到db的过程时,它就可以很好地工作了。
我正在使用以下配置。似乎连接正在突然关闭,一旦我重新启动进程,它会再次创建一个新的连接。我必须配置任何 parameterDataSource 或者 connection pool 为了保持 connection 打开而不是突然关闭?
数据源

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource"
        destroy-method="close">
        <property name="driverClassName" value="com.sybase.jdbc4.jdbc.SybDriver" />
        <property name="url" value="******"/>
        <property name="username" value="*******"/>
        <property name="password" value="*******" />
        <property name="connectionProperties" value="ENCRYPT_PASSWORD=true;JCE_PROVIDER_CLASS=org.bouncycastle.jce.provider.BouncyCastleProvider" />             

    </bean>

数据源

<bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate"
    scope="prototype">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref local="dataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>************</value> 
        </list>
    </property>
</bean>

堆栈跟踪

org.springframework.dao.TransientDataAccessResourceException: Hibernate operation: could not inspect JDBC autocommit mode; SQL [???]; JZ0C0: Connection is already closed.; nested exception is java.sql.SQLException: JZ0C0: Connection is already closed.
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:106)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
    at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
    at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
Caused by: java.sql.SQLException: JZ0C0: Connection is already closed.
    at com.sybase.jdbc4.jdbc.ErrorMessage.raiseError(Unknown Source)
    at com.sybase.jdbc4.jdbc.SybConnection.checkConnection(Unknown Source)
    at com.sybase.jdbc4.jdbc.SybConnection.getAutoCommit(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
    at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:99)
    at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:63)
    at com.sun.proxy.$Proxy0.getAutoCommit(Unknown Source)
    at org.hibernate.jdbc.ConnectionManager.isAutoCommit(ConnectionManager.java:189)
    at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:243)
    at org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:417)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1701)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
    at com.b2conshore.testing.B2COnshoreSybaseTesting$1.doInHibernate(B2COnshoreSybaseTesting.java:39)
    at com.b2conshore.testing.B2COnshoreSybaseTesting$1.doInHibernate(B2COnshoreSybaseTesting.java:1)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
    ... 2 more

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题