数据源 DataSourcejava
javax.sql 接口 DataSourcesql
从1.4版本开始数据库
DataSource 对象表示的物理数据源的链接。做为 DriverManager 设施的替代项,DataSource 对象是获取链接的首选方法。实现 DataSource 接口的对象一般在基于 JavaTM Naming and Directory Interface (JNDI) API 的命名服务中注册。服务器
DataSource 接口由驱动程序供应商实现。共有三种类型的实现:app
基本实现 - 生成标准 Connection 对象分布式
链接池实现 - 生成自动参与链接池的 Connection 对象。此实现与中间层链接池管理器一块儿使用。this
分布式事务实现 - 生成一个 Connection 对象,该对象可用于分布式事务,而且几乎始终参与链接池。此实现与中间层事务管理器一块儿使用,而且几乎始终与链接池管理器一块儿使用。spa
DataSource 对象的属性在须要时能够修改。例如,若是将数据源移动到另外一个服务器,则可更改与服务器相关的属性。其优势是,由于能够更改数据源的属性,因此任何访问该数据源的代码都无需更改。日志
经过 DataSource 对象访问的驱动程序不会向 DriverManager 注册。经过查找操做检索 DataSource 对象,而后使用该对象建立 Connection 对象。使用基本的实现,经过 DataSource 对象获取的链接与经过 DriverManager 设施获取的链接相同。对象
方法摘要
Connection getConnection()
尝试创建与此 DataSource 对象表示的数据源的链接。
Connection getConnection(String username, String password)
尝试创建与此 DataSource 对象表示的数据源的链接。
int getLoginTimeout()
获取此数据源尝试链接到某一数据库时能够等待的最长时间,以秒为单位。
PrintWriter getLogWriter()
检索此 DataSource 对象的日志 writer。
void setLoginTimeout(int seconds)
设置数据源尝试链接到某一数据库时将等待的最长时间,以秒为单位。
void setLogWriter(PrintWriter out)
将此 DataSource 对象的日志 writer 设置为给定的 java.io.PrintWriter 对象。
从1.6时开始
Method Summary
Connection getConnection()
Attempts to establish a connection with the data source that this DataSource object represents.
Connection getConnection(String username, String password)
Attempts to establish a connection with the data source that this DataSource object represents.
Methods inherited from interface javax.sql.CommonDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
1.4 增长包javax.sql
1.5 增长子包avax.sql.rowset
1.6 类改造CommonDataSource等
1.7 类改造RowSetFactory等
1.8 内部代码修改