JDBC 的應用連接Oracle 遇到問題,錯誤如下:
ORA-12505,TNS:listener does not currently know of SID given in connect descriptor TheConnection descriptor used by the client was。
我在DB 層面配置了靜態注冊,並且GLOBAL_DBNAME和SID_NAME 不一樣,以往的配置都是一樣的,所以沒有發現這個問題。
(SID_DESC =
(GLOBAL_DBNAME = dave)
(ORACLE_HOME =D:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = NEWCCS)
)
Oracle Listener 動態注冊 與 靜態注冊
http://blog.csdn.net/tianlesoftware/article/details/5543166
在網上google 了一下,發現JDBC Thin Driver 的formats 有三種格式:
jdbc:oracle:thin:@//<host>:<port>/<service_name>
Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE
注意這裡的格式,@後面有//, 這是與使用SID的主要區別。
這種格式是Oracle 推薦的格式,因為對於集群來說,每個節點的SID 是不一樣的,但是SERVICE_NAME 確可以包含所有節點。
jdbc:oracle:thin:@<host>:<port>:<SID>
Example: jdbc:oracle:thin:192.168.2.1:1521:X01A
Note: Support for SID is being phased out. Oracle recommends that users switch over to usingservice names.
jdbc:oracle:thin:@<TNSName>
Example: jdbc:oracle:thin:@GL
Note:
Support for TNSNames was added in the driver release 10.2.0.1
Oracle 是11gR2
Listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = dave)
(ORACLE_HOME =D:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = NEWCCS)
)
)
Tnsnames.ora
DVD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dave)
)
)