20

What is the difference between Spring DriverManagerDataSource and apache BasicDataSource? Which of them is preferable and in which situations?

Thank you.

Nazar Sobchuk
  • 297
  • 1
  • 7
  • 17

2 Answers2

21

As per the Spring documentation

This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

If you need a "real" connection pool outside of a J2EE container, consider Apache's Jakarta Commons DBCP or C3P0. Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full connection pool beans, supporting the same basic properties as this class plus specific settings (such as minimal/maximal pool size etc).

Also read Controlling database connections

When using Spring's JDBC layer, you obtain a data source from JNDI or you configure your own with a connection pool implementation provided by a third party. Popular implementations are Apache Jakarta Commons DBCP and C3P0. Implementations in the Spring distribution are meant only for testing purposes and do not provide pooling.

Community
  • 1
  • 1
NINCOMPOOP
  • 46,742
  • 15
  • 123
  • 158
3

From Spring DriverManagerDataSource API:

This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

In other words, it may be OK for tests but in real application use Apache DBCP

Evgeniy Dorofeev
  • 124,221
  • 27
  • 187
  • 258