无法使用Connection类连接数据库。

huangapple go评论73阅读模式
英文:

Not able to connect to database using Connection class

问题

我真的不知道以下代码有什么问题。我能够从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开发人员中提到了相同的连接详细信息,它可以正常工作。

异常线程中的内容:

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

希望这可以帮助你解决问题。

英文:

I really dont know what is wrong in the below code. I am able to connect from SQL developer but through JDBC it is giving exception.

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");
		
	}

}

same connection details I am mentioning in SQL DEveloper and it is working.

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

答案1

得分: 1

正确的JDBC URL是:
> "jdbc:oracle:thin:@100.92.25.90:1521/PDB1.pvtsub1.xxxxx0011iad.oraclevcn.com"

您需要将1521PDB1之间的**":"改为"/"**。

英文:

The correct jbdc url is :
> "jdbc:oracle:thin:@100.92.25.90:1521/PDB1.pvtsub1.xxxxx0011iad.oraclevcn.com"

you need to change the ":" between 1521 and PDB1 by "/"

huangapple
  • 本文由 发表于 2020年8月4日 17:41:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63244132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定