Listener refused the connection with the following error: ORA-12505, TNS:listene

J2EE 码拜 9年前 (2015-04-22) 830次浏览 0个评论

Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

我想请问 我本地写了一个java 访问oralce 的程序

我本地安装oracle 客户端 
 plsql 可以正常使用 
但是java的程序无法访问 数据库
我也需要配置监听文件么?,应该怎么配置?

Listener refused the connection with the following error: ORA-12505, TNS:listene
mark mark mark
Listener refused the connection with the following error: ORA-12505, TNS:listene
20分
打开Oracle的 listener.ora 文件:
oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora)
 
修改前:
# listener.ora Network Configuration File: /app/oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /app/oracle/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = suse10.site)(PORT = 1521))
    )
  )
——————————————————————————————————————————
修改后:
# listener.ora Network Configuration File: /app/oracle/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /app/oracle/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = ORCL) 
      (ORACLE_HOME = /app/oracle/oracle/product/10.2.0/db_1)
      (SID_NAME = ORCL)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = suse10.site)(PORT = 1521))
    )
  )
 
上面的红色文字是增加的内容。 (ORCL — 是你的SID 数据库名)

Listener refused the connection with the following error: ORA-12505, TNS:listene
http://anthon-lx.iteye.com/blog/811460
Listener refused the connection with the following error: ORA-12505, TNS:listene
引用 5 楼 fangmingshijie 的回复:

http://anthon-lx.iteye.com/blog/811460

那文章我看过了 ,请看清我的标题,那个文章有个一楼 就是我的提问 谢谢!

Listener refused the connection with the following error: ORA-12505, TNS:listene
程序看看。。
Listener refused the connection with the following error: ORA-12505, TNS:listene
找到这个目前下。
D:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN
用记事本打开 listener.ora 文件;文件如下:
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = D:\oraclexe\app\oracle\product\11.2.0\server)
      (PROGRAM = extproc)
    )
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = D:\oraclexe\app\oracle\product\11.2.0\server)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 0HRTOR4KLCB9KTG)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

最后我在 eclipse 把SID 修改成最后那两位数:XE
代码如下:
public class testjdbc {
public static void main(String[] args) throws Exception {
Class.forName(“oracle.jdbc.OracleDriver”);
String url = “jdbc:oracle:thin:@localhost:1521:xe”;
String user = “XXX”;
String password = “XXX”;
Connection con=DriverManager.getConnection(url, user, password);
System.out.println(con);
}
}

最后运行结果:oracle.jdbc.driver.T4CConnection@1813fac

Listener refused the connection with the following error: ORA-12505, TNS:listene
楼主解决了吗?我也遇到和你一样的问题了
Listener refused the connection with the following error: ORA-12505, TNS:listene
登陆之前不能联网
Listener refused the connection with the following error: ORA-12505, TNS:listene
连接数据库的时候的SID 写错了,改成自己的SID就能连接了,我的是这么解决的

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Listener refused the connection with the following error: ORA-12505, TNS:listene
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!