日期:2014-05-17  浏览次数:20796 次

关于Servlet Destroy()的调用问题
	public void destroy(){
System.out.println("destroy the servlet");
//super.destroy();
int temp=Integer.parseInt(getServletContext().getAttribute("countNum").toString());  //获取application的值
try {
Class.forName("com.mysql.jdbc.Driver");
connection=DriverManager.getConnection("jdbc:mysql://localhost/webdb","iheng","iheng");
state=connection.createStatement();
state.executeQuery("update table_1 set WebCount="+temp+" where id='102'");    //将获得的值写入数据库
connection.close();
} catch (ClassNotFoundException | SQLException e1) {
// TODO 自动生成的 catch 块
e1.printStackTrace();
}
}


问题代码如上,据网上说,当Tomcat(我用的服务器是Tomcat)关闭的时候,就会自动调用Destroy()方法,但是我关掉Tomcat之后,查询数据库,数据库里面的字段值并没有被更新,这是什么原因呢? 是Destroy()没有正确被调用么?

求知情者指教~~~~~~
Servlet 数据库 Tomcat Java

------解决方案--------------------
会调用destory方法的,至于你说的没调用destroy方法,可能你是直接把虚拟机关闭了