今天jdbc链接数据库报错,java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list
百度了下,原因如下,jdbc连接oracle数据库两种方式,使用sid和servicename的写法略有区别。
使用jdbc连接oracle时url有2种格式
格式一: Oracle JDBC Thin using an SID:jdbc:oracle:thin:@host:port:SID
Example: jdbc:oracle:thin:@localhost:1521:orcl
格式二: Oracle JDBC Thin using a ServiceName:
jdbc:oracle:thin:@//host:port/service_name
Example:jdbc:oracle:thin:@//localhost:1521/orcl.city.com
注意这里的格式,@后面有//, port后面:换成了/,这种格式是Oracle 推荐的格式,因为对于集群来说,每个节点的SID 是不一样的,但是SERVICE_NAME 确可以包含所有节点。
参考https://blog.csdn.net/u012062455/article/details/52442838