JDBC连接数据库的异常,在命令行sqlplus scott/tiger能连接数据库,sid没问题啊,Jar包也导入了,改成localhost也没用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:
127.0.0.1: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 test.TestJDBC.main(TestJDBC.java:10)

解决方案 »

  1.   

    sqlplus scott/tiger@tns_name
    用这种方式你肯定登陆不了ORA-12505: TNS:listener does not currently know of SID given in connect descriptor 
    Cause: The listener received a request to establish a connection to a database or other service. The connect descriptor received by the listener specified a SID for an instance (usually a database instance) that either has not yet dynamically registered with the listener or has not been statically configured for the listener. This may be a temporary condition such as after the listener has started, but before the database instance has registered with the listener.
    Action: 
    - Wait a moment and try to connect a second time.- Check which instances are currently known by the listener by executing: lsnrctl services <listener name>- Check that the SID parameter in the connect descriptor specifies an instance known by the listener.- Check for an event in the listener.log file.
      

  2.   

    不懂啊,我是说在myeclipse里写JDBC连接不上数据库,有那个异常,也不知道怎么回事……在学校里行的,自己电脑上就不行,怎么回事呢
      

  3.   

    一般就是你的listener.ora配置有问题,或者和tnsnames.ora不配套。可以把这两个文件的内容贴上来看看。
      

  4.   

    监听配置了吗?用tnsping  服务名看看通不通,在看一下有无防火墙,如有把防火墙关了,试下