我试图通过java代码手动连接到oracle数据库,但是我遇到了这个错误。
java代码
public static void main(String[] args) throws Exception {
//database info
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@//HOST:1521/SERVICE"
String username = "*******";
String password = "*******";
//Connect
try{
Connection conn = DriverManager.getConnection(url, username, password);
} catch (Exception e){
System.out.println("convertStackTraceToString(e---------------------------------------");
System.out.println(convertStackTraceToString(e));
System.out.println("printStackTrace(e---------------------------------------");
Thread.sleep(100); // Avoids timing side effect with println and printStackTrace
e.printStackTrace();
}
java堆栈跟踪
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:858)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:793)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:57)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:747)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:562)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at Main.main(Main.java:33)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:404)
at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:179)
at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:119)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:571)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:548)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:682)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:661)
at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:202)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:340)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1600)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:591)
... 14 more
Caused by: java.io.IOException: Connection refused, socket connect lapse 2 ms. /SCRUB.SCRUB.SCRUB.SCRUB 1521 0 1 true
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:233)
at oracle.net.nt.ConnOption.connect(ConnOption.java:174)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:510)
... 21 more
Caused by: java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:482)
at java.base/sun.nio.ch.Net.connect(Net.java:474)
at java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:694)
at java.base/java.nio.channels.SocketChannel.open(SocketChannel.java:194)
at oracle.net.nt.TimeoutSocketChannel.connect(TimeoutSocketChannel.java:99)
at oracle.net.nt.TimeoutSocketChannel.<init>(TimeoutSocketChannel.java:77)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:192)
... 23 more
我已经检查了凭据和url,它们似乎在另一个系统/网络上工作。我没有访问实际数据库本身的权限,只有要使用的凭据和url。我还可以确认服务器和端口之间的连接。
太好了!
暂无答案!
目前还没有任何答案,快来回答吧!