简体   繁体   中英

CAn't connect to Oracle with Spring Boot and Hibernate

I have a working Spring Boot app (1.2) that uses Postgres. Today I am trying to switch it to Oracle, but when I try to connect I get an exception that says:

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection 

And below that,

Caused by: java.net.ConnectException: Connection refused

So of course that looks like bad credentials, but I know they are good, and they are working in Oracle SQL Developer just fine. I'm baffled. Here are my properties file entries:

# Properties for Hibernate and Oracle
spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//earth-db-11:5121/stardev
spring.datasource.username=ops$abcdefg
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

The only idea I have is that there is a $ in the user name, and I have tried escaping it and putting double quotes around it.

Any ideas?

Thanks...

UPDATE:

Many thanks to BonanzaOne, I did have the port number wrong. Correcting that results in a new error:

java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

I looked it up of course, but I don't follow what its telling me:

ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Cause: The listener received a request to establish a connection to a database
or other service. The connect descriptor received by the listener specified a
service name for a service (usually a database service) that either has not    yet
dynamically registered with the listener or has not been statically configured
for the listener. This may be a temporary condition such as after the listener
has started, but before the database instance has registered with the listener.

Still, SQL Explorer connects fine.

That exception means that the Oracle listener is not up, or you are trying to connect to a listener that don't exist/not accessible.

My guess is that you trying the wrong port "5121". Oracle default port is 1521 .

Can you try with that and see what happens?


From the FAQ there are basically two ways of composing your JDBC string URL:

Old syntax

jdbc:oracle:thin:@[HOST][:PORT]:SID

New syntax

jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE

My guess is that you are using the wrong syntax-SID/Service name combination, in other words, you are using the new syntax that requires the SERVICE name, but you are using the SID name to do it.

Try this: jdbc:oracle:thin:@earth-db-11:1521:stardev

Or maybe find out the Service name and apply it to the new syntax that you are using, instead of the SID name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM