public interface DataSource extends CommonDataSource, Wrapper
对,这DataSource
对象代表的物理数据源的连接工厂。一种替代的DriverManager
设施,一DataSource
对象获得连接的首选方法。实现DataSource
接口通常是与命名服务基于java™命名和目录注册一个对象(JNDI)API。
的DataSource
接口是由一个驱动程序供应商实施。有三种类型的实现:
Connection
对象Connection
对象将自动参与连接池。此实现与一个中间层连接池管理器一起工作。Connection
对象可用于分布式事务几乎总是参与连接池。此实现与一个中间层事务管理器一起工作,并且几乎总是与一个连接池管理器一起工作。一个DataSource
对象的属性,可以进行修改,必要时。例如,如果数据源被移动到不同的服务器,服务器的属性就可以改变了。好处是,因为数据源的属性可以被更改,任何代码访问该数据源不需要改变。
一个驱动器,通过DataSource
对象不与DriverManager
登记本身访问。相反,一个DataSource
检索对象虽然查找操作,然后用来创建一个Connection
对象。一个基本的实现,连接通过一个DataSource
对象是通过DriverManager
设备所连接的相同。
DataSource
的实施必须包括一个公共的无参数构造函数。
Modifier and Type | Method and Description |
---|---|
Connection |
getConnection()
试图建立这种
DataSource 对象代表数据源连接。
|
Connection |
getConnection(String username, String password)
试图建立这种
DataSource 对象代表数据源连接。
|
getLoginTimeout, getLogWriter, getParentLogger, setLoginTimeout, setLogWriter
isWrapperFor, unwrap
Connection getConnection() throws SQLException
试图建立这种DataSource
对象代表数据源连接。
SQLException
-如果一个数据库访问错误发生
SQLTimeoutException
-当司机已确定由
setLoginTimeout
方法指定超时值已经超过,至少试图取消当前的数据库连接的尝试
Connection getConnection(String username, String password) throws SQLException
试图建立这种DataSource
对象代表数据源连接。
username
-数据库用户的连接是其代表
password
-用户的密码
SQLException
-如果一个数据库访问错误发生
SQLTimeoutException
-当司机已确定由
setLoginTimeout
方法指定超时值已经超过,至少试图取消当前的数据库连接的尝试
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.