简体   繁体   English

无法使用Spring Boot和Hibernate连接到Oracle

[英]CAn't connect to Oracle with Spring Boot and Hibernate

I have a working Spring Boot app (1.2) that uses Postgres. 我有一个使用Postgres的Spring Boot应用程序(1.2)。 Today I am trying to switch it to Oracle, but when I try to connect I get an exception that says: 今天我正在尝试将其切换到Oracle,但是当我尝试连接时,我得到一个异常,说:

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. 当然,这看起来像是糟糕的凭据,但我知道它们很好,而且他们在Oracle SQL Developer中工作得很好。 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. 非常感谢BonanzaOne,我的端口号错了。 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. 不过,SQL Explorer连接正常。

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. 该异常意味着Oracle侦听器未启动,或者您尝试连接到不存在/不可访问的侦听器。

My guess is that you trying the wrong port "5121". 我的猜测是你尝试错误的端口“5121”。 Oracle default port is 1521 . Oracle默认端口是1521

Can you try with that and see what happens? 你可以尝试一下,看看会发生什么?


From the FAQ there are basically two ways of composing your JDBC string URL: FAQ中,基本上有两种组成JDBC字符串URL的方法:

Old syntax 旧语法

jdbc:oracle:thin:@[HOST][:PORT]:SID JDBC:预言:瘦:@ [HOST] [:端口]:SID

New syntax 新语法

jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE JDBC:预言:瘦:@ // [HOST] [:端口] / 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. 我的猜测是你使用了错误的语法-SID /服务名称组合,换句话说,你使用的是需要SERVICE名称的新语法,但是你使用SID名称来执行它。

Try this: jdbc:oracle:thin:@earth-db-11:1521:stardev 试试这个: 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. 或者找出服务名称并将其应用于您正在使用的新语法,而不是SID名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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