eclipse Io 异常:网络适配器无法建立连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22337901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Io exception: The Network Adapter could not establish the connection
提问by user3046703
I am using a tomcat application server and connecting to Oracle DB. There is a file called ojdbc14-10g.jar
in the project. In the jsp page I am opening a connection to the database and getting some information. However, when I refresh the page, for many times I get the following error:
我正在使用 tomcat 应用程序服务器并连接到 Oracle DB。项目中有一个名为的文件ojdbc14-10g.jar
。在jsp 页面中,我打开与数据库的连接并获取一些信息。但是,当我刷新页面时,多次出现以下错误:
java.sql.SQLException:Io exception: The Network Adapter could not establish the connection.
java.sql.SQLException:Io 异常:网络适配器无法建立连接。
String driverName = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521/xe";
String user = "system";
String password = "1234";
String patientName = null;
String sql1 = "select * from patient where pid=?";
try{
Class.forName(driverName);
con = DriverManager.getConnection(url, user, password);
ps = con.prepareStatement(sql1);
ps.setString(1,patientId);
rs = ps.executeQuery();
if(rs.next()){
//Some data is coming
}
con.close();
}
catch(SQLException sqe){
out.println(sqe);
}
Also, I am using this code in other jsp pages, and also, for more than four or five refreshes, I am getting the same error.
此外,我在其他 jsp 页面中使用了此代码,而且,对于超过四五次的刷新,我遇到了同样的错误。
Could you give me any suggestions?
你能给我任何建议吗?
回答by Parvatha
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
java.sql.SQLException: Io 异常: 网络适配器无法建立连接
The above Exception
will occur whenever your DB is not reachable.
Once your DB is up refresh/bounce your servers and it will resolve the issue.
Exception
每当您的数据库无法访问时,就会发生上述情况。一旦您的数据库启动刷新/反弹您的服务器,它将解决问题。
回答by Bhushan Shimpi
Whenever you see a Network Adapter could not establish the connection, you have either the wrong SQL Developer URL or you have a basic SQL*Net connectivity issue! This error is most likely caused by one of these factors:
每当您看到网络适配器无法建立连接时,您要么使用了错误的 SQL Developer URL,要么遇到了基本的 SQL*Net 连接问题!此错误很可能是由以下因素之一引起的:
You are using the wrong URL
The wrong port number or IP address (or DNS host name) was used
The listener is not configured properly
The listener process (service) is not running. You can re-start it with the "lsnrctl start" command or on Windows by starting the listener service.
您使用了错误的网址
使用了错误的端口号或 IP 地址(或 DNS 主机名)
监听器配置不正确
侦听器进程(服务)未运行。您可以使用“lsnrctl start”命令或在 Windows 上通过启动侦听器服务来重新启动它。
回答by Codemaker
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
java.sql.SQLException: Io 异常: 网络适配器无法建立连接
This occurs due to the mismatch in Database name or the port is currently used by another service. You can first check the Database name if it is ok then it caused by the port issue or the network adapter could not be started.
发生这种情况是由于数据库名称不匹配或端口当前被其他服务使用。您可以先检查数据库名称是否正常,然后是端口问题或网络适配器无法启动引起的。
It is resolved by executing the following in the command prompt as administrator
以管理员身份在命令提示符下执行以下命令即可解决
netstat -ano | findstr 8080 taskkill /f /pid pid_number
netstat -ano | findstr 8080 taskkill /f /pid pid_number
If it could not resolve your issue then it can be solve by the following code
如果它不能解决您的问题,那么可以通过以下代码解决
lnsrctl start
lnsrctl 启动
回答by santhakr
The Network Adapter could not establish the connection can happen when the connection url/string is wrong.
当连接 url/string 错误时,可能会发生网络适配器无法建立连接。
The connection string that you use doesn't seem to be right. Should it be jdbc:oracle:thin:@localhost:1521:xe
instead of jdbc:oracle:thin:@localhost:1521/xe
? (Note that it is ':'
instead of '/'
)
您使用的连接字符串似乎不正确。应该jdbc:oracle:thin:@localhost:1521:xe
代替jdbc:oracle:thin:@localhost:1521/xe
吗?(请注意,它是':'
代替'/'
)
回答by shakul
just restart your listner services using commands given below.. Starting and Shutting Down the Listener
只需使用下面给出的命令重新启动您的侦听器服务.. 启动和关闭侦听器
The Oracle listener is set up to start automatically whenever your server machine is restarted. However, when your system encounters unforeseen circumstances, or when you have manually stopped the listener, you can restart it at the command line. To do so, use the following:
Oracle 侦听器设置为在您的服务器计算机重新启动时自动启动。但是,当您的系统遇到不可预见的情况时,或者您手动停止了侦听器时,您可以在命令行重新启动它。为此,请使用以下命令:
lsnrctl start
lsnrctl 启动
You can use Enterprise Manager to stop the listener. To do so, navigate to the Listener: listener_name page by clicking Listener on the Home page. To shut down the listener, click Stop.
您可以使用企业管理器来停止侦听器。为此,请通过单击主页上的 Listener 导航到 Listener: listener_name 页面。要关闭侦听器,请单击停止。
You can also stop it at the command line using the following:
您还可以使用以下命令在命令行中停止它:
lsnrctl stop
lsnrctl 停止