JTDS and JBOSS JDBC Connection Pool Problem, any solution? Maybe a custom ValidConnectionChecker?

前端 未结 3 1355
粉色の甜心
粉色の甜心 2021-02-10 22:15

I\'m facing a weird production problem. Environment is the following:

  • JBOSS 4.0.2
  • SQL Server 2005
  • Driver JTDS 1.2.5

From time to

相关标签:
3条回答
  • 2021-02-10 22:43

    Try changing your driver class line to net.sourceforge.jtds.jdbcx.JtdsDataSource. net.sourceforge.jtds.jdbc.Driver doesn't implement the javax.sql.ConnectionPoolDataSource interface. source: http://jtds.sourceforge.net/faq.html#features

    0 讨论(0)
  • 2021-02-10 22:45

    Probably too late the solution, but I am stuck with the jtds driver here. Hope this saves half an hour of your productive time.

    The fix is to specify a validationQuery to the Apache dbcp2 Connection Pool implementation. For jtds/sql server I specified the spring configuration as follows:

    <bean id="sqlServerDS" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close" >
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="defaultReadOnly" value="true" />
        <property name="validationQuery" value="select 1" />
    </bean>
    

    In case you are not using Spring, call setValidationQuery method on BasicDataSource in your java code.

    BasicDataSource bds = new BasicDataSource();
    bds.setValidationQuery("select 1");
    
    0 讨论(0)
  • 2021-02-10 23:02

    Connection.isValid() isn't implemented in JTDS. I found even catching the exception and forcing a complete restart of the connection didn't work.

    0 讨论(0)
提交回复
热议问题