Myeclipse连接oracle数量提示ORA-12504, TNS:listener was not given the SID in CONNECT_DATA。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Myeclipse连接oracle数量提示ORA-12504, TNS:listener was not given the SID in CONNECT_DATA。相关的知识,希望对你有一定的参考价值。

源程序为:
package com;
import java.sql.*;
public class TestJDBC1
/**
* @param args
*/
public static void main(String[] args)
// TODO Auto-generated method stub
Connection conn = null;
try
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:gonghanqiang","scott","tiger");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from dept");
while(rs.next())
System.out.println(rs.getInt("deptno"));


rs.close();
st.close();
conn.close();
catch (ClassNotFoundException e)
// TODO Auto-generated catch block
e.printStackTrace();
catch (SQLException e)
// TODO Auto-generated catch block
e.printStackTrace();



导入的oracle驱动为:ojdbc6.jar
运行结果为:
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12504, TNS:listener was not given the SID in CONNECT_DATA

at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at com.TestJDBC1.main(TestJDBC1.java:12)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12504, TNS:listener was not given the SID in CONNECT_DATA

at oracle.net.ns.NSProtocol.connect(NSProtocol.java:385)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more

参考技术A 你的数据库监听配置有问题吧,检查下你数据库的tnsnames.ora配置文件本回答被提问者采纳

Navicat Premium 连接oracle 提示ORA-01017:用户名/口令无效;登陆被拒绝

 

Navicat Premium 连接oracle,密码明明是对的,还是提示 ORA-01017:用户名/口令无效;登陆被拒绝。而用Pl/SQL 连接没有问题。

 

Navicat连接Oracle报错

 

其实用户名和密码是对的,但还是会报错,这时,打开选项卡高级,默认角色为“SYSBDA”改为“Default”,重新“测试连接”即可。

 

Navicat连接Oracle报错

Navicat连接Oracle报错

 

以上是关于Myeclipse连接oracle数量提示ORA-12504, TNS:listener was not given the SID in CONNECT_DATA。的主要内容,如果未能解决你的问题,请参考以下文章

MyEclipse连接Oracle12c测试报java.sql.SQLException: ORA-01017: 用户名/口令无效; 登录被拒绝

myeclipse连接oracle

Navicat:连接Oracle时,提示ORA-28547,Cannot load OCI DLL.193,ORA-03135错误

Navicat:连接Oracle时,提示ORA-28547,Cannot load OCI DLL.193,ORA-03135错误

java开发---关于ORA00604和ORA12705

Java连接Oracle11g的时候提示ORA-12505