2

我真的不知道下面的代码有什么问题。我能够从 SQL 开发人员连接,但通过 JDBC 它给出了异常。

package com.shruti.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;

public class ReadData {
    
    public static void main(String[] args) throws Exception {
        
        Class.forName("oracle.jdbc.driver.OracleDriver"); 
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@100.92.25.90:1521:PDB1.pvtsub1.xxxxx0011iad.oraclevcn.com","gotapps","WElcome***#11");
        
    }

}

我在 SQL DEveloper 中提到的相同连接细节并且它正在工作。

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
 
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:801)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:782)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:704)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.onkar.jdbc.ReadData.main(ReadData.java:10)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 
    at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:273)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:318)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1481)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:540)
    ... 6 more
4

1 回答 1

1

正确的 jbdc 网址是:

“jdbc:oracle:thin:@100.92.25.90:1521/PDB1.pvtsub1.xxxxx0011iad.oraclevcn.com”

您需要将1521PDB1之间的“:”更改为“/”

于 2020-08-04T09:48:21.093 回答