簡體   English   中英

無法使用Spring Boot和Hibernate連接到Oracle

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

我有一個使用Postgres的Spring Boot應用程序(1.2)。 今天我正在嘗試將其切換到Oracle,但是當我嘗試連接時,我得到一個異常,說:

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

在那之下,

Caused by: java.net.ConnectException: Connection refused

當然,這看起來像是糟糕的憑據,但我知道它們很好,而且他們在Oracle SQL Developer中工作得很好。 我很困惑。 這是我的屬性文件條目:

# 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

我唯一的想法就是用戶名中有一個$,我試圖轉義並在其周圍加上雙引號。

有任何想法嗎?

謝謝...

更新:

非常感謝BonanzaOne,我的端口號錯了。 更正會導致新錯誤:

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

當然,我查了一下,但我沒有按照它告訴我的說法:

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.

不過,SQL Explorer連接正常。

該異常意味着Oracle偵聽器未啟動,或者您嘗試連接到不存在/不可訪問的偵聽器。

我的猜測是你嘗試錯誤的端口“5121”。 Oracle默認端口是1521

你可以嘗試一下,看看會發生什么?


FAQ中,基本上有兩種組成JDBC字符串URL的方法:

舊語法

JDBC:預言:瘦:@ [HOST] [:端口]:SID

新語法

JDBC:預言:瘦:@ // [HOST] [:端口] / SERVICE

我的猜測是你使用了錯誤的語法-SID /服務名稱組合,換句話說,你使用的是需要SERVICE名稱的新語法,但是你使用SID名稱來執行它。

試試這個: jdbc:oracle:thin:@ earth-db-11:1521:stardev

或者找出服務名稱並將其應用於您正在使用的新語法,而不是SID名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM