当前位置: 动力学知识库 > 问答 > 编程问答 >

spring - Oracle 11g DBCP The Network Adapter could not establish the connection

问题描述:

I'm traied to connect oracle with Spring and 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)

I'm able to connect via SQLDeveloper with this properties:

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...

Think it's not important, but i use the datasource with 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>

网友答案:

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

网友答案:

The db might be setup not to allow these kind of connections. Try this:

telnet localhost 1521

To see if you can connect on that port.

分享给朋友:
您可能感兴趣的文章:
随机阅读: