连接 jdbc Oracle10g 错误 ,JDBC代码无问题,服务也启动,连接字符串也是对的,但是在eclipse 下报错,错误信息如下:
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
The Connection descriptor used by the client was:
localhost:1521:orcl
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:279)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:318)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:343)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:147)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:545)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at cn.com.db.DBAccess.getConnection(DBAccess.java:33)
at cn.com.db.DBAccess.main(DBAccess.java:95)
Null
在CMD下snrctl status ,tnsping orcl 显示都正常。
在pl/SQL下用
select open_mode from v$database;
show parameter instance;
select INSTANCE_NAME from v$instance;
sqlplus sys/oracle@orcl
查询都显示正常,就是用pl/sql 登录时 填“数据库名” orcl 就无法登陆,报ora -12514
l最后有效的解决方法:
修改listener.ora文件
原listener.ora文件:
# listener.ora Network Configuration File: D:\oracle\product\10.1.0\Db_4\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = D:\oracle\product\10.1.0\Db_4)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
)
修改后的文件:
---------------------------------------------------------------------------------------
# listener.ora Network Configuration File: D:\oracle\product\10.1.0\Db_4\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = D:\oracle\product\10.1.0\Db_4)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = D:\oracle\product\10.1.0\Db_4)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
)
-----------------------------------------------------------------
如果错误还存在,也可以那试一下:
set oracle_sid=<sid_name>
sqlplus /nolog
connect sys/pwd as sysdba
start