Oracle 11g DBCP 网络适配器无法建立连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13108616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle 11g DBCP The Network Adapter could not establish the connection
提问by Evgeni Dimitrov
I'm traied to connect oracle with Spring and DBCP.
我试图将 oracle 与 Spring 和 DBCP 连接起来。
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521/ORCL" />
<property name="username" value="PMSYSDB" />
<property name="password" value="********" />
</bean>
but I get: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (IO Error: The Network Adapter could not establish the connection)
但我得到: Could not get JDBC Connection; nested exception is org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (IO Error: The Network Adapter could not establish the connection)
I'm able to connect via SQLDeveloper with this properties:
我可以通过 SQLDeveloper 使用以下属性进行连接:
Hostname: localhost
Port : 1521
SID : ORCL
username: PMSYSDB
password:
so my database is up and running... Firewall is off... The database and the tomcat are on the same machine...
所以我的数据库已启动并正在运行......防火墙已关闭......数据库和tomcat在同一台机器上......
Think it's not important, but i use the datasource with Spring Security:
认为这并不重要,但我将数据源与 Spring Security 一起使用:
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select username, password, enabled
from users where username=?"
authorities-by-username-query="
select u.username, ur.authority from users u, user_roles ur
where u.user_id = ur.user_id and u.username =? "
/>
</authentication-provider>
</authentication-manager>
回答by Evgeni Dimitrov
The problem was that I used this syntax jdbc:oracle:thin:@localhost:1521/ORCL
for the connection string. After /
Oracle expects service name and not SID (ORCL is my SID).
The solution was to change the connection sring to jdbc:oracle:thin:@localhost:1521:ORCL
问题是我jdbc:oracle:thin:@localhost:1521/ORCL
对连接字符串使用了这种语法。在/
Oracle 需要服务名称而不是 SID(ORCL 是我的 SID)之后。解决方案是将连接环更改为jdbc:oracle:thin:@localhost:1521:ORCL
回答by Solubris
The db might be setup not to allow these kind of connections. Try this:
db 可能设置为不允许此类连接。尝试这个:
telnet localhost 1521
To see if you can connect on that port.
看看你是否可以在那个端口上连接。
回答by sail kargutkar
Refresh the listener after changing and manipulating the
更改和操作后刷新侦听器
C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN\listener.ora
C:\oraclex\app\oracle\product\11.2.0\server\network\ADMIN\listener.ora
and
和
C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN\tnsnames.ora
C:\oraclex\app\oracle\product\11.2.0\server\network\ADMIN\tnsnames.ora
don't forget to refresh listener using the following command in CMD(Run as administrator).
不要忘记在 CMD(以管理员身份运行)中使用以下命令刷新侦听器。
lsnrctl stop
lsnrctl start
After this wait for 1-2 minutes and click on test.
在此之后等待 1-2 分钟,然后单击测试。