看看如下servlet 代码,是否有未关闭的连接

Sky_Wuhan 2007-12-25 10:14:12
看看如下servlet 代码,是否有未关闭的连接:
以下servlet用来接收编辑后的资料然后更新数据库存后返回显示页面,但是现在只要提交几次后就会报错,数据源连接池满.不知道是不是下面代码有没关闭的类

package dev;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.sql.DataSource;
import dev.DatabaseConn;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class upinfo extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
private Connection conn;
private Statement stmt;
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
// out.print("tests");
String sid=request.getParameter("sid");
String tile=request.getParameter("zt");
String frm=request.getParameter("frm");
String content=request.getParameter("content");

try {
conn.close();
conn=dev.DatabaseConn.getConnection();
stmt=conn.createStatement();
// out.print("tes14ts");
stmt.executeUpdate("update nt01 set N001='"+tile+"',n002='"+frm+"',n003='"+content+"' where id="+sid+"");
stmt.close();
conn.close();
}
catch (Exception ex) {
ex.printStackTrace();
}

response.sendRedirect("admin/info/list.jsp");
//RequestDispatcher requestDispatcher=request.getRequestDispatcher("admin/info/list.jsp");
//requestDispatcher.forward(request,response);
}
//Clean up resources
public void destroy() {

}
}
...全文
43 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
老紫竹 2007-12-26
  • 打赏
  • 举报
回复

try {
conn=dev.DatabaseConn.getConnection();
stmt=conn.createStatement();
// out.print("tes14ts");
stmt.executeUpdate("update nt01 set N001='"+tile+"',n002='"+frm+"',n003='"+content+"' where id="+sid+"");
}
catch (Exception ex) {
ex.printStackTrace();
}finally{
if(smtp!=null) try{ stmt.close(); }catch(Exception ex){}
if(conn!=null) try{ conn.close(); }catch(Exception ex){}
}

50,545

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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