一、两者对比
相同点:
Simple implementation of the standard JDBC
DataSource
interface, configuring a plain old JDBCDriver
via bean properties, and returning a newConnection
from everygetConnection
call.NOTE: 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.
简单实现标准JDBC DataSource
接口,DriverManager
通过bean属性配置普通的旧JDBC ,并Connection
从每次getConnection
调用返回一个新的。
注意:此类不是实际的连接池; 它实际上并没有池连接。它只是简单替代完整的连接池,实现相同的标准接口,但在每次调用时都创建新的连接。
不同点:
NOTE: Within special class loading environments such as OSGi, this class is effectively superseded by
SimpleDriverDataSource
due to general class loading issues with the JDBC DriverManager that be resolved through direct Driver usage (which is exactly what SimpleDriverDataSource does).注意:在特殊类加载环境(如OSGi)中,
SimpleDriverDataSource
由于JDBC DriverManager的一般类加载问题可以通过直接驱动程序使用来解决此类(这正是SimpleDriverDataSource所做的事情),因此该类实际上已被取代。
二、通过构造器查看两者的不同
2.1、DriverManagerDataSource
//构造函数和描述
DriverManagerDataSource()
//bean风格配置的构造函数。
DriverManagerDataSource(String url)
//使用给定的JDBC URL创建新的DriverManagerDataSource,而不是为JDBC访问指定用户名或密码。
DriverManagerDataSource(String url, Properties conProps)
//使用给定的JDBC URL创建新的DriverManagerDataSource,而不是为JDBC访问指定用户名或密码。
DriverManagerDataSource(String url, String username, String password)
//使用给定的标准DriverManager参数创建新的DriverManagerDataSource。
2.2、SimpleDriverDataSource
//构造函数和描述
SimpleDriverDataSource()
//bean风格配置的构造函数。
SimpleDriverDataSource(Driver driver, String url)
//使用给定的标准Driver参数创建一个新的DriverManagerDataSource。
SimpleDriverDataSource(Driver driver, String url, Properties conProps)
//使用给定的标准Driver参数创建一个新的DriverManagerDataSource。
SimpleDriverDataSource(Driver driver, String url, String username, String password)
//使用给定的标准Driver参数创建一个新的DriverManagerDataSource。
2.3、总结
SimpleDriverDataSource由于JDBC DriverManager的一般类加载问题可以通过直接驱动程序使用来解决此类(这正是SimpleDriverDataSource所做的事情),因此DriverManagerDataSource实际上已被取代。