問題描述:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was:
10.12.162.84:1521:xxxx
oracle數據的tnsnames.ora中配置的是:SERVICE_NAME =xxxx。經過查詢發現,是jdbc中的連接串使用的不正確。Java JDBC Thin Driver 連接 Oracle有三種方法,如下:
格式一: Oracle JDBC Thin using a ServiceName: jdbc:oracle:thin:@//<host>:<port>/<service_name> Example: jdbc:oracle:thin:@//192.168.2.1:1521/XE 注意這里的格式,@后面有//, 這是與使用SID的主要區別。 這種格式是Oracle 推薦的格式,因為對於集群來說,每個節點的SID 是不一樣的,但是SERVICE_NAME 確可以包含所有節點。 格式二: Oracle JDBC Thin using an SID: 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. 格式三:Oracle JDBC Thin using a TNSName: jdbc:oracle:thin:@<TNSName> Example: jdbc:oracle:thin:@GL Note: Support for TNSNames was added in the driver release 10.2.0.1
Service_name 和Sid的區別
Service_name:該參數是由oracle8i引進的。在8i以前,使用SID來表示標識數據庫的一個實例,但是在Oracle的並行環境中,一個數據庫對應多個實例,這樣就需要多個網絡服務名,設置繁瑣。為了方便並行環境中的設置,引進了Service_name參數,該參數對應一個數據庫,而不是一個實例,而且該參數有許多其它的好處。該參數的缺省值為Db_name. Db_domain,即等於Global_name。一個數據庫可以對應多個Service_name,以便實現更靈活的配置。該參數與SID沒有直接關系,即不必Service name 必須與SID一樣。Sid是數據庫實例的名字,每個實例各不相同。
---整理自網絡
