Java通过JDBC连接Oracle数据库提示Listener refused the connection with the following error:

Question:

Java通过JDBC连接Oracle数据库提示Listener refused the connection with the following error:ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

Solution:

JDBC连接Oracle数据库的三种格式及查询SID,ServiceName,TNSName的详细实例说明https://blog.csdn.net/Ninewind/article/details/89574892

通过SID链接Oracle数据库

 

JDBC通过SID连接Oracle数据库
格式 : jdbc:oracle:thin:@<host>:<port>:<SID>
示例 : jdbc:oracle:thin:@localhost:1521:orcl11

如果是通过SID连接的Oracle数据库则在CMD中敲击下面的命令查询SID

Java新手查看端口号(也就是示例中1251)后面是:的就是SID连接的Oracle数据库

SQLPLUS / AS SYSDBA
 
select value from v$parameter where name='instance_name';

  Java通过JDBC连接Oracle数据库提示Listener refused the connection with the following error:

 

通过ServiceName连接Oracle数据库

JDBC通过ServiceName连接Oracle数据库
格式 : jdbc:oracle:thin:@//<host>:<port>/<service_name>
示例 : jdbc:oracle:thin:@//localhost:1521/orcl11

如果是通过ServiceName连接的Oracle数据库则在CMD中敲击下面的命令查询ServiceName

Java新手查看@后面是 // 而且端口号(也就是示例中1251)后面是 / 的就是ServiceName连接的Oracle数据库

SQLPLUS / AS SYSDBA
 
select value from v$parameter where name='service_names';

  Java通过JDBC连接Oracle数据库提示Listener refused the connection with the following error:

 

查看自己是通过何种方式连接的Oracle数据库

然后将其改为正确的SID或者ServiceName问题就会解决了