Sowmya
Sowmya

Reputation: 473

Connect to Oracle database from hibernate which is in my local

I have installed Oracle 12c in my local and connected in SQL developer tool as below :

Connection Name : TEST
Username : SYSTEM
Password: 
Connection Type : TNS Role : default
Network Alias: ORCL

But when I am trying to connect this using hibernate as below :

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@//localhost:1521/TEST"/>
<property name="username" value="SYSTEM"/>
<property name="password" value=""/>
</bean>

I get error as : oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

Did I miss any step?

Upvotes: 2

Views: 2489

Answers (2)

Sowmya
Sowmya

Reputation: 473

I solved the issue by changing the connection type in Oracle Sql Developer as below :

Connection Type : Basic
Role : Default
Host : localhost
Port : 1521
Service Name : orcl.user.com [you can get service name from tnsnames.ora file]

And try URL as "jdbc:oracle:thin:@//localhost:1521/orcl.user.com" from hibernate config.

By this setting I am able to access Oracle DB.

Upvotes: 1

BobC
BobC

Reputation: 4416

I think your url should be ... 1521/ORCL, rather than 1521/TEST

Upvotes: 0

Related Questions