开发者

initSql property and DriverManagerDataSource

I configured the following DriverManagerDataSource for my junits

<bean id="myDS"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${ds.driver}"/>
    <property name="url" value="${ds.url}"/>
    <property name="username" value="${ds.username}"/>
    <property name="password" value="${ds.password}"/>
</bean>

Now I want to add the initSql property to make the DS execute an sql command at connection creation time. I tried the following configuration but it doesn't work.

<bean id="myDS"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${ds.driver}"/>
    <property name="url" value="${ds.url}"/>
    <property name="username" value="${ds.username}"/>
    <开发者_Python百科property name="password" value="${ds.password}"/>
    <property name="connectionProperties">
      <props>
        <prop key="initSql">select set_limit(0.1)</prop>
      </props>
    </property>
  </bean>

How to add the initSql property on a DriverManagerDataSource ?


You can take a look at DBCP basic datasource, that supports specifying a set of sqls to be executed at the time of creation of connections.

The DriverManagerDatasource is not recommended to be used for deployment as it doesn't do any connection pooling. It is better to use DBCP or CP30.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜