Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22506

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>

Upvotes: 2

Views: 17720

Answers (3)

sail kargutkar
sail kargutkar

Reputation: 1

Refresh the listener after changing and manipulating the

C:\oraclexe\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

don't forget to refresh listener using the following command in CMD(Run as administrator).

lsnrctl stop
lsnrctl start  

After this wait for 1-2 minutes and click on test.

Upvotes: 0

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22506

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

Upvotes: 5

Solubris
Solubris

Reputation: 3753

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.

Upvotes: 1

Related Questions