我正在使用 tomcat 应用程序服务器并连接到 Oracle DB。项目中有一个名为ojdbc14-10g.jar
的文件。在 jsp 页面中,我打开与数据库的连接并获取一些信息。但是,当我刷新页面时,多次出现以下错误:
java.sql.SQLException:Io exception: The Network Adapter could not establish the connection.
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 页面中使用此代码,而且,对于超过四到五次的刷新,我遇到了相同的错误。
你能给我一些建议吗?
最佳答案
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
每当您的数据库无法访问时,就会发生上述异常
。
一旦您的数据库启动,刷新/恢复您的服务器,问题就会得到解决。
关于java - Io异常: The Network Adapter could not establish the connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337901/