为什么DataSource
接口(interface)未定义 JDBC 指定的标准数据源属性 - DataSource ?
使用 DataSource
类型的引用 ds
,我无法像这样设置以下属性:
public DbUtil(DataSource ds, String dbName, String port){
ds.setServerName(dbName);
ds.setPortNumber(port);
}
最佳答案
因为您不应该传入这些值,这与普通的旧DriverManager
不同。数据源通常在容器上配置,并且只能使用 JNDI 进行查找。
如果您再次开始传递这些值,则会破坏可配置数据源的全部意义。
这是来自 API 的引用。
The DataSource interface is implemented by a driver vendor.
A DataSource object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property for the server can be changed. The benefit is that because the data source's properties can be changed, any code accessing that data source does not need to be changed.
关于java - 数据源属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10687453/