我正在使用 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 页面中使用此代码,而且,对于超过四到五次刷新,我得到了同样的错误。
你能给我一些建议吗?