gpt4 book ai didi

Oracle JDBC 连接被拒绝(仅来自 jdbc 代码)

转载 作者:行者123 更新时间:2023-12-02 07:28:43 30 4
gpt4 key购买 nike

我在尝试连接到远程 Oracle 数据库时收到 Connection denied

我可以成功地远程登录到相同的 IP 地址和端口,我什至可以使用相同的凭据通过 SQL Developer 或 IntelliJ Idea 的 Database 选项卡进行连接,但是当我从我的代码中尝试时,我得到了异常(exception)。

注意:我正在使用 Ubuntu、IntelliJ IDEA、Tomcat 7、Oracle JDBC 驱动程序 v7.0。

以下独立代码引发相同的异常:

public static void main(String[] argv) {

System.out.println("-------- Oracle JDBC Connection Testing ------");

try {

Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Where is your Oracle JDBC Driver?");
e.printStackTrace();
return;
}

System.out.println("Oracle JDBC Driver Registered!");

Connection connection = null;

try {
connection = DriverManager.getConnection(
"jdbc:oracle:thin:10.1.1.27:1521:xe", "user", "password");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}

if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
}

输出:

Oracle JDBC Driver Registered!

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.greenmile.web.DBConnectionTest.main(DBConnectionTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:445)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:464)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
... 12 more

Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:162)
at oracle.net.nt.ConnOption.connect(ConnOption.java:133)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:411)
... 17 more

Connection Failed! Check output console

最佳答案

将 jdbc 连接字符串 "jdbc:oracle:thin:10.1.1.27:1521:xe" 替换为 "jdbc:oracle:thin:@10.1.1.27:1521/xe"

explanation here

关于Oracle JDBC 连接被拒绝(仅来自 jdbc 代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24539579/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com