tomcat+mysql数据库连接报错

hx_uestc 2011-08-14 01:05:46
严重: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);
}
}
请教这是什么错误?
...全文
322 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hx_uestc 2011-08-15
  • 打赏
  • 举报
回复
嗯,我关闭了pw后,不再报错了。
晋冬子 2011-08-14
  • 打赏
  • 举报
回复
应该是有个线程还是什么的没有关闭 不太明白
hx_uestc 2011-08-14
  • 打赏
  • 举报
回复
pw也需要关闭?不是response自动关闭吗?
晋冬子 2011-08-14
  • 打赏
  • 举报
回复
PrintWriter pw = res.getWriter();
这里的pw需要关闭把
LMAOhuaNL 2011-08-14
  • 打赏
  • 举报
回复
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();
}
}

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

81,092

社区成员

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

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