英文:
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"
您需要将1521和PDB1之间的**":"改为"/"**。
英文:
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 "/"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论