Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring DriverManagerDataSource vs apache BasicDataSource

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

Thank you.

like image 864
Nazar Sobchuk Avatar asked Jul 30 '13 10:07

Nazar Sobchuk


2 Answers

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.

like image 94
AllTooSir Avatar answered Oct 18 '22 14:10

AllTooSir


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

like image 34
Evgeniy Dorofeev Avatar answered Oct 18 '22 12:10

Evgeniy Dorofeev