Spring DriverManagerDataSource vs apache BasicDataSource

后端 未结 2 920
小蘑菇
小蘑菇 2021-02-05 07:38

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

Thank you.

相关标签:
2条回答
  • 2021-02-05 07:39

    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.

    0 讨论(0)
  • 2021-02-05 07:44

    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

    0 讨论(0)
提交回复
热议问题