日期:2014-05-19  浏览次数:20947 次

SQL/SQL 能连接上数据库,JDBC不能连上数据库 急......
公司 用的是Oracle 9i Pl/SQL能连接上服务器上的数据库,JDBC就不能,重启服务不行,清理环境不行
代码
Java code

public static void main(String[] args) throws ClassNotFoundException, SQLException {
         String url="jdbc:oracle:thin:@192.168.1.4:1521:performancedb";
         String driverClass="oracle.jdbc.driver.OracleDriver";
         String name="ywk";
         String password="password";
         Class.forName(driverClass);
         Connection connection= DriverManager.getConnection(url,name,password);
         Statement statement =connection.createStatement();
         ResultSet resultSet= statement.executeQuery("select * from t_user");
         System.out.println(resultSet);
    }



错误
Java code

Exception in thread "main" 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:
192.168.1.4:1521:performancedb

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.a.b.TestJDBC.main(TestJDBC.java:16)



在线等 急

------解决方案--------------------
performancedb

数据库的名字不对,别说什么用PL-SQL连接好使,PL-SQL连接用的是网络服务名。
------解决方案--------------------
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
数据库的SID指定的不对
------解决方案--------------------
url有问题吧
------解决方案--------------------
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor


String url="jdbc:oracle:thin:@192.168.1.4:1521:performancedb";

应该是这个的问题 ,你查看一下 你的服务中的 ....TNSListener的服务的名字是什么?


------解决方案--------------------
探讨
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor


String url="jdbc:oracle:thin:@192.168.1.4:1521:performancedb";

应该是这个的问题 ,你查看一下 你的服务中的 ....TNSListener的服务的名字是什……

------解决方案--------------------
探讨
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor


String url="jdbc:oracle:thin:@192.168.1.4:1521:performancedb";

应该是这个的问题 ,你查看一下 你的服务中的 ....TNSListener的服务的名字是什……