严重:The web application [/myWebSite] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it.This is very likely to create a memory leak.
代码如下:
package com.uestc;import javax.servlet.http.*;
import java.io.*;
import java.sql.*;public class LoginCl extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse res) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{

PrintWriter pw = res.getWriter();
HttpSession hs = req.getSession(true);
String u = req.getParameter("user");
String p = req.getParameter("passwd");
String error = "login in again please";

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/spdb?user=root&password=root");
stmt = conn.createStatement();
rs = stmt.executeQuery("select passwd from users where username='"+u+"' limit 0,1");
if(rs.next()) {
String passwd = rs.getString(1);
if(passwd.equals(p)) {
hs.setAttribute("pass","ok");
res.sendRedirect("wel?user="+u+"&passwd="+p);
} else {
res.sendRedirect("login?error="+error);
}
}
 else {

res.sendRedirect("login?error="+error);
}
}catch(Exception ex) {
ex.printStackTrace();
}finally{
try{
if(rs!= null) {
rs.close();
}
if(stmt != null) {
stmt.close();
}
if(conn != null) {
conn.close();
}
}catch(Exception ex) {
ex.printStackTrace();
}
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res) {
this.doGet(req,res);
}
}
请教这是什么错误?

解决方案 »

  1.   

    LZ是看韩顺平的那个servlet的视频啊。。
    小弟我也遇到了这个问题。。搞了一上午了还没弄明白。
    输入账号和密码以后直接跳转到LoginCl  这里什么内容都不显示。、、
      

  2.   

    The web application [/myWebSite] appears to have started a thread named [MySQL Statement Cancellation Timer] but has failed to stop it.This is very likely to create a memory leak.
    //说你有一个开始的线程名字是MySQL Statement Cancellation Timer,应该是数据库没有关
    try {
    处理数据代码 } catch (Exception e) {
    e.printStackTrace();
    }finally{
    //关闭数据库链接
    try {
    if(rs != null){
    rs.close();
    }
    if(st != null){
    st.close();
    }
    if(conn != null){
    conn.close();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
      

  3.   

    PrintWriter pw = res.getWriter();
    这里的pw需要关闭把
      

  4.   

    pw也需要关闭?不是response自动关闭吗?