日期:2014-05-17  浏览次数:20822 次

oracle只能连接orcl库,无论程序里指定什么库名
使用plsqldeveloper:
scott,tiger连接GAOCONG库可以成功。
java程序语句:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:GAOCONG", "scott", "tiger");
程序连接报错:
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

主要问题:无论在程序里指定什么库名,程序就要去连接orcl库。我本机没有orcl库。自从拿了别人一个项目运行后就出现了这个问题,至今没有解决,请教各位了,谢谢。
------最佳解决方案--------------------
DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:GAOCONG",
改成
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:GAOCONG",
------其他解决方案--------------------
配置的localhost你觉得有问题吗???

Rayn412552703
------其他解决方案--------------------
你的数据的名字就叫GAOCONG吗?

Rayn412552703
------其他解决方案--------------------
引用:
你的数据的名字就叫GAOCONG吗?

Rayn412552703

是的,我的数据库名字就是GAOCONG,并且没有其他的库。我这个项目是拿别人的到本机运行的,原来项目中写的是orcl库,我改成了我自己的GAOCONG库,但是程序仍然去连接orcl库,因为我自己没有orcl库,因此报错。
------其他解决方案--------------------
你先确定你改的代码被编译了。

也就是说,你改的是src,class文件重新编译了吗?
------其他解决方案--------------------
引用:
DriverManager.getConnection("jdbc:oracle:thin:localhost:1521:GAOCONG",
改成
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:GAOCONG",


正解,谢谢,我还是太马虎了。确实要写个@。不过不写@居然数据库会自己去连orcl。。。
------其他解决方案--------------------
及时结贴是一种美德