我正在使用 tomcat 应用程序服务器并连接到 Oracle DB。项目中有一个名为 ojdbc14-10g.jar
的文件。在 jsp 页面中,我打开到数据库的连接并获取一些信息。但是,当我刷新页面时,多次出现以下错误:
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);
}
此外,我在其他 jsp 页面中使用此代码,而且,对于超过四次或五次刷新,我遇到了同样的错误。
你能给我什么建议吗?
原文由 user3046703 发布,翻译遵循 CC BY-SA 4.0 许可协议
每当您看到网络适配器无法建立连接时,您要么有错误的 SQL Developer URL,要么有基本的 SQL*Net 连接问题!此错误很可能是由以下因素之一引起的:
您使用了错误的网址
使用了错误的端口号或 IP 地址(或 DNS 主机名)
监听器配置不正确
侦听器进程(服务)未运行。您可以使用“lsnrctl start”命令或在 Windows 上通过启动侦听器服务来重新启动它。