Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently
来源:互联网 发布:java微信公众平台框架 编辑:程序博客网 时间:2024/05/18 19:20
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:711)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:558)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at demo1.DBHelp.getCon(DBHelp.java:16)
at demo1.DBHelp.main(DBHelp.java:28)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:272)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
... 8 more
明显的,这是由于监听程序不能识别连接标识符中的数据库SID,到网上查了一下
网上的解决方法如下:找到tnsnames.ora文件使用记事本或者其他的工具打开,注意,我这是oracle12c的文件的路径,其他的oracle的不同的版本在不同的路径下
D:\oracle\app\Administrator\product\12.1.0\dbhome_1\NETWORK\ADMIN下的tnsnames.ora文件的内容如下
# tnsnames.ora Network Configuration File: D:\oracle\app\Administrator\product\12.1.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_TEST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
LISTENER_ORACLE12C =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORACLE12C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = oracle12c)
)
)
//把原来红色的部分改成上面所示的内容,上面加绿色的部分是当初你安装时数据库的实例名称,
D:\oracle\app\Administrator\product\12.1.0\dbhome_1\NETWORK\ADMIN的listener.ora文件
文件的内容如下:
# listener.ora Network Configuration File: D:\oracle\app\Administrator\product\12.1.0\dbhome_1\network\admin\listener.ora# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\oracle\app\Administrator\product\12.1.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\oracle\app\Administrator\product\12.1.0\dbhome_1\bin\oraclr12.dll")
)
(SID_DESC =)
(GLOBAL_DBNAME = oracle12c)
(ORACLE_HOME = D:\oracle\app\Administrator\product\12.1.0\dbhome_1)
(SID_NAME = oracle12c)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
红色的部分是添加上去的,保存,然后重新启动oracle服务。
测试的内容如下所示
package demo1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBHelp {
private static String URL = "jdbc:oracle:thin:@127.0.0.1:1521:oracle12";
private static String USERNAME = "system";
private static String PASSWORD = "940109";
public static Connection getCon(){
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
if(conn!=null)
System.out.println("connect successful");
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(new DBHelp().getCon());
}
public static void close(Connection con,Statement sm,ResultSet rs){
try {
if(con!=null){
con.close();
}
if(sm!=null){
sm.close();
}
if(rs != null){
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
//就不会再报错了
connect successful
oracle.jdbc.driver.T4CConnection@1edf1c96
也就是当初在安装oracle12c是自己改了实例的名称,如果是按照默认的实例进行的安装的话,那么上面的内容基本上是不需要自己修改的。
不是按照默认的实例进行的安装。
- Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently
- Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently
- Listener refused the connection with the following error:ORA-12505, TNS:listener does not currently
- 状态: 失败 -测试失败: Listener refused the connection with the following error: ORA-12505, TNS:listener does
- 状态: 失败 -测试失败: Listener refused the connection with the following error: ORA-12505, TNS:listener does
- java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list
- java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:lis
- java.sql.SQLException: Listener refused the connection with the following error: ORA-12505, TNS:list
- java.sql.SQLException: Listener refused the connection with the following error:ORA-12505
- 解决数据库连接报错Listener refused the connection with the following error: ORA-12505
- 解决数据库连接报错Listener refused the connection with the following error: ORA-12505
- ORA-12514错误:Listener refused the connection with the following&
- Listener refused the connection with the following error:
- Listener refused the connection with the following error
- Listener refused the connection with the following error 错误解
- Listener refused the connection with the following error 错误解决
- Listener refused the connection with the following error 错误解决
- Listener refused the connection with the following error 错误解决
- matlab调用c程序
- 助您开启高效编程之旅:10款云端IDE推荐
- 字符串编辑距离与拼写错误检查
- MainLoop.c (4)结构体PGconn 和 PGresult
- CABasicAnimation(基础属性动画)的简单使用
- Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently
- 第二十章 内存等空间管理类的实现
- Oracle,MySQL,SQL Server数据库的数据类型
- Android--取得系统服务
- QImage 图像格式小结
- .Net相关的证书
- 【BZOJ】【P2730】【HNOI2012】【矿场搭建】【题解】【dfs】
- 《设计模式之禅》——策略模式
- Jenkins系列—安装与配置