近期在項目中使用JDBC連接數據庫的時候報錯:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
192.217.14.203:11524:database
通過錯誤信息 ORA-12505可以知道,是SID無法識別。此時需要檢查當前使用的是SID還是service_name。
查詢數據庫SID方法:
select instance_name from V$instance;
查詢數據庫service_name方法
select value from v$parameter where name = 'service_names';
在配置JDBC數據庫連接地址的時候,SID和service_name的格式是不同的
- 使用SID配置地址格式
jdbc:oracle:thin:@<host>:<port>:<SID>
例如:
jdbc:oracle:thin:@182.168.1.223:1522:aaa
- 使用service_name配置地址格式
jdbc:oracle:thin:@//<host>:<port>/<service_name>
根據使用的SID和service_name 來使用相應格式進行配置,最后再啟動服務就不會報錯了。