[英]Getting “java.sql.SQLException: Io exception: The Network Adapter could not establish the connection”
The below is my code. 下面是我的代码。 I wanted to connect to Employee table from Oracle.
我想从Oracle连接到Employee表。
public static void main(String[] args) {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection connection = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
Statement statement = connection.createStatement();
ResultSet resultset = statement.executeQuery("select 'Connected' from dual");
resultset.next();
String s = resultset.getString(1);
System.out.println(s);
statement.close();
connection.close();
} catch (Exception e) {
System.out.println("The exception raised is:" + e);
}
}
I am always getting the error as "The exception raised is:java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" 我总是收到错误消息,因为“引发的异常是:java.sql.SQLException:Io异常:网络适配器无法建立连接”
I tried turning off the firewall, but no luck. 我尝试关闭防火墙,但是没有运气。 Could someone please help me in resolving the issue.
有人可以帮我解决问题。
Did you try telnet'ing that db? 您是否尝试过远程登录该数据库? something like...
就像是...
Telnet localhost 1521
Just to check if there is a process listing to that port. 仅检查该端口是否有进程列表。
It can be three thins: 它可以是三个瘦:
Ok, when My team was in a black box server with an url for connecting to the Database we didn't know what was the error and so we created a UDL File that can make this test. 好的,当我的团队位于黑匣子服务器中,该URL带有用于连接数据库的URL时,我们不知道发生了什么错误,因此我们创建了可以进行此测试的UDL文件 。 Check this tutorial for connection testing With that you can test the three of them and see if you have a real connection with the Database.
查看本教程进行连接测试。使用该教程,您可以测试它们中的三个,并查看是否与数据库建立了真正的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.