首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

关于Servlet Destroy()的调用有关问题

2013-04-27 
关于Servlet Destroy()的调用问题public void destroy(){System.out.println(destroy the servlet)//su

关于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方法,可能你是直接把虚拟机关闭了

热点排行