0

Java - spring 3

Following is the data source connect is configured in spring-context file.

Problem is it is SingleConnectionDataSource and it does not work in multi threading, what is other choice which works in multi threading ?

<bean id="dataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
        <property name="driverClassName" value="net.sourceforge.jtds.jdbcx.JtdsDataSource"/>
        <property name="url" value="${dataSource.url}"/>
        <property name="username" value="${dataSource.username}"/>
        <property name="password" value="${dataSource.password}"/>
    </bean>
d-man
  • 57,473
  • 85
  • 212
  • 296

2 Answers2

1
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
  <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver"/>

Is what we always use to connect to sql server. Maven :

 <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • is there any one available in org.springframework.jdbc.datasource ? – d-man Feb 20 '13 at 15:49
  • I don't know what you specific needs are, they are listed here : http://static.springsource.org/spring/docs/1.2.x/api/org/springframework/jdbc/datasource/package-summary.html – NimChimpsky Feb 20 '13 at 15:51
  • what about DriverManagerDataSource ? – d-man Feb 20 '13 at 15:52
  • I don;t think spring provides full blown connection pools if that is what you want, I would just use the one I provided. A vote down with no reason, lovely. – NimChimpsky Feb 20 '13 at 16:07
  • look at my answer i think you should also change datasource to simpledatasource – d-man Feb 20 '13 at 19:07
-1

With a pooled data source, the connections in the pool are not actually closed, they just get returned to the pool. However, when the application is shut down, those connections to the database should be properly and actually closed, which is where the final cleanup comes in.

Incidentally, the c3p0 project is pretty much dead in the water, I recommend you use Apache Commons DBCP instead, it's still being maintained.

Apache Commons DBCP check this link for code configure BasicDataSource as bean in web.xml

Community
  • 1
  • 1
d-man
  • 57,473
  • 85
  • 212
  • 296
  • its not dead in the water at all, it was last updated on the 9th of feb (11 days before date of question) http://sourceforge.net/projects/c3p0/ – NimChimpsky Feb 20 '13 at 20:33
  • I still recommend Apache's product i have seen in many products this lib is being used, i tried and it worked for me. – d-man Feb 22 '13 at 20:35