gpt4 book ai didi

java - 数据源属性

转载 作者:行者123 更新时间:2023-12-01 17:31:13 26 4
gpt4 key购买 nike

为什么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 whennecessary. For example, if the data source is moved to a differentserver, the property for the server can be changed. The benefit isthat because the data source's properties can be changed, any codeaccessing that data source does not need to be changed.

关于java - 数据源属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10687453/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com