user3240621
user3240621

Reputation: 29

Spring and jtds.jdbc.Driver parameters

I have Spring application with MS SQL Server using jtds, how can I find all parameters for the data source? Now I have only:

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

I want to set also: timeout.login, timeout.connection, timeout.query and timeout.reconnect

Upvotes: 3

Views: 7023

Answers (1)

M. Deinum
M. Deinum

Reputation: 124760

DriverManagerDataSource isn't intended to be used as a production ready DataSource implementation. It is nice for testing or quickly showing an application but it should/must end there. For production you want to use a real DataSource which does connection pooling and a lot of other things.

Instead of the DriverManagerDataSource you want to use something like tomcat-jdbc or BoneCP for a datasource. Those will all allow you to set various options.

If you really want to keep using the DriverManagerDataSource pass the properties into the connectionProperties element. See here for the properties which you can set.

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="connectionProperties">
        <props>
            <prop entry="socketTimeout">${timeout.connection}</prop>
            <prop entry="loginTimeout">${timeout.login}</prop>                               
        </props>
    </property>
</bean>

As DriverManagerDataSource isn't a proper connection pool I would expect a value for timeout.reconnect to be useless. A connection is opened at the start of a transaction and closed as soon as the transaction has committed.

Upvotes: 2

Related Questions