急!急!急! Tomcat4.0莫名其妙的自动关闭

tolywang 2003-03-01 05:41:54
急!急!急!Tomcat4.0每运行几天就会莫名其妙的自动关闭, 有时候首页可以进入,但是到连接ODBC用户登陆时偶尔会出现Exception : general error . 的错误(大多数时候不会报错). 听说是sql中的连接Connection 对象没有在运行完毕之后关闭 , 但是我关闭连接对象之后还是会出现异常现象 . 请各位帮帮忙 .
以下是登陸用的部分Code :
<%
Connection conn ;
Statement stmt ;
ResultSet rs ;
String temp_userid,temp_password,login_userid,sql,message;
message="";
temp_userid = "";
temp_password = "";
login_userid = "";
if(request.getParameter("login")!=null){
try{
temp_userid = request.getParameter("userid");
temp_password = request.getParameter("password");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:user","","");
stmt = conn.createStatement();
sql = "SELECT * FROM c_user_t WHERE user_id='" + temp_userid + "' AND pass_word='" + temp_password + "'";
rs = stmt.executeQuery(sql);
}catch(Exception e){
out.println("<br>"+"Sorry");
out.println("<br>Error get database connection,process terminated.<br>Please try again or contact administrator.");
out.println("<br>Error message:" +e);
return;
}
if (rs.next()){
login_userid = rs.getString("user_id");
if (stmt!=null){stmt.close();}
if (conn!=null){conn.close();}
message = login_userid;
response.sendRedirect("mainframe.jsp");
session.setAttribute("username",temp_userid);
session.setAttribute("version","EN");
return;
}else{
message = "Invalid user ID or password!";
}

}
if(temp_userid==null){
temp_userid="";
}
%>

......

<%conn.close();%>




...全文
29 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
firemica 2003-03-02
  • 打赏
  • 举报
回复
最好使用数据库提供的jdbc类!
CQP 2003-03-01
  • 打赏
  • 举报
回复
使用连接池
zxhong 2003-03-01
  • 打赏
  • 举报
回复
if (stmt!=null){stmt.close();}
if (conn!=null){conn.close();}
---->
if (stmt!=null){
stmt.close();
stmt=null;}
if (conn!=null){
conn.close();
conn=null;
}

建议用jdbc,j-o桥很不稳定,特别在访问量较大时很容易崩溃
huqile 2003-03-01
  • 打赏
  • 举报
回复
用共享连接池

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧