尝试连接到设置为只读的数据库时,无法建立连接。我收到以下错误:
Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not
establish the connection)
应用程序需要以读写模式运行,然后通过仅检查连接对象的isReadOnly属性自动将开关处理为只读。连接到读写数据库时应用程序正确运行,但当我更改为下面的连接字符串时(删除了安全信息),应用程序失败。我已经验证连接字符串是正确的,所以问题不在那里。
ca.businesssolutions.nbs.jdbc.connect=jdbc:oracle:thin:unicorn_read_only/password@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=9999)))(CONNECT_DATA=(SID=SBSBTST)(SERVER=DEDICATED)))
我无法弄清楚从哪里开始寻找。我继承了应用程序并且不确定它是否是弹簧框架限制或我缺少的其他设置。
数据源的弹簧配置为:
<bean id="dataSource" class="ca.businesssolutions.nbs.server.base.datasource.MyBasicDataSource"
destroy-method="close">
<!--url and driver class name are set through Configuratoin object.-->
<property name="initialSize" value="10"/>
<property name="maxActive" value="-1"/>
<property name="validationQuery" value="SELECT 1 FROM DUAL"/>
<property name="accessToUnderlyingConnectionAllowed" value="true"/>
</bean>
数据源构造函数:
public MyBasicDataSource() {
super();
setUrl(Configuration.get(Configuration.CONNECT));
setDriverClassName(Configuration.get(Configuration.DRIVER_NAME));
//The initial number of connections that are created when the pool is started.
int numConnections = 10;
try {
numConnections = Integer.parseInt(Configuration.get(Configuration.NUMBER_OF_CONNECTIONS));
} catch (Exception exception) {
// Do nothing.
}
setInitialSize(numConnections);
//The maximum number of active connections that can be allocated from this pool at the same time, or non-positive for no limit.
setMaxActive(-1);
setValidationQuery("SELECT 1 FROM DUAL");
setAccessToUnderlyingConnectionAllowed(true);
DataAccessObject.setDataSource(this);
}
还有什么可以帮助?
答案 0 :(得分:1)
读/写和只读连接字符串有什么区别?是否任何机会输入错字?您是否尝试过来自其他工具(但来自同一主机)的连接字符串?尝试在连接困难的同一台计算机上使用Java GUI工具。使用复制/粘贴与您的确切连接字符串。
如果这也不起作用,您可能会遇到无法解析的主机名,防火墙问题或其他问题。如果它在同一台计算机上工作,请发表评论。