JSP连接MySQL出现at java.lang.Thread.run

J2EE 码拜 9年前 (2015-04-03) 1443次浏览 0个评论

我建了一个 UserBeanCL类如下
//进行帐号验证的Users处理类,封装对users表进行的操作
package com.liang;
import java.sql.*;
import javax.servlet.http.*;
public class UserBeanCL {
private Connection ct = null;
private Statement st = null;
private ResultSet rs = null; 
public boolean checkUser(String user,String passwd){
boolean check=false;
try{ 
//建立连接
connectDB con=new connectDB();
ct=con.getConnection();
st=ct.createStatement();
//查询数据库中是否存在该用户,若存在则将该用户密码取出做进一步验证
rs=st.executeQuery(“select userpasswd from users where username=”””+user+””””);
if(rs.next())//验证密码是否正确
{
String DBpasswd=rs.getString(1);
if(DBpasswd.equals(passwd)){
check=true;
}
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
if(rs!=null)
{
rs.close();
rs=null;
}
if(ct!=null)
{
ct.close();
ct=null;
}
if(st!=null)
{
st.close();
st=null;
}
}catch(Exception e){
e.printStackTrace();
}
}
return check;
}

//释放连接
public void close(){
try{
if(rs!=null)
{
rs.close();
rs=null;
}
if(ct!=null)
{
ct.close();
ct=null;
}
if(st!=null)
{
st.close();
st=null;
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}

连接MySQL类如下:
//连接MySQL
package com.liang;
import java.sql.*;
public class connectDB {
private Connection ct=null;
private String url = “jdbc:mysql://localhost:3306/bookDB”; //定位MySQL
public Connection getConnection(){
try{
//建立与MySQL的连接
   Class.forName(“org.gjt.mm.mysql.Driver”).newInstance();
   Class.forName(“com.mysql.jdbc.Driver”);
   ct = DriverManager.getConnection(url, “root”, “”);
}catch(Exception ex){
ex.printStackTrace();
}
return ct;
}
}

在登录用的JSP里
<%@ page language=”java” import=”java.util.*,com.liang.*” pageEncoding=”UTF-8″%>
<%response.setContentType(“text/html;charset=UTF-8″);%>
<html>
<head>
<title>登录界面</title>
<style type=”text/css”>
.titlestyle 
background-color: #09C;
font-family: Verdana, Geneva, sans-serif;
font-weight: bold;
font-size: 36px;
color: #F00;
font-style: italic;
}
.backgroundstyle {
background-color: #0F6;
}
</style></head>

<body class=”backgroundstyle”>
<div align=”center”>
  <h1 class=”titlestyle”>图书管理系统<br>
</h1>
</div>
<form action=”LoginCL.jsp” method=post>
<p align=”center”>用户名:
  <input type=text name=username>
</p>
<p align=”center”>  密码 :
  <input name=passwd type=”password”></p>
<p align=”center”><input type=”image” src=”images/bt34.bmp” value=登录>
</p>
</form>
  <p align=”center”><input type=”image” src=”images/bt13.bmp” value=”注册”>
</p>
</body>
</html>
还有LoginCL.jsp:
<%@ page language=”java” import=”java.util.*,com.liang.*” pageEncoding=”UTF-8″%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
  <head>
    <base href=”<%=basePath%>”>
    
    <title>My JSP “”LoginCL.jsp“” starting page</title>
    
<meta http-equiv=”pragma” content=”no-cache”>
<meta http-equiv=”cache-control” content=”no-cache”>
<meta http-equiv=”expires” content=”0″>    
<meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
<meta http-equiv=”description” content=”This is my page”>
<!–
<link rel=”stylesheet” type=”text/css” href=”styles.css”>
–>

  </head>
  
  <body>
<%
//获得用户名和密码
String u=request.getParameter(“username”);
String p=request.getParameter(“passwd”);
//调用UserBeanCL,完成验证
UserBeanCL ubc=new UserBeanCL();
if(ubc.checkUser(u,p))
{
response.sendRedirect(“main.jsp“);
}else{
response.sendRedirect(“index.jsp“);
}
 %>
  </body>
</html>
问题是输入正确的帐号密码后,依然登不进去,帐号密码是数字不存在中文乱码问题,执行到st=ct.createStatement();显示at java.lang.Thread.run(Unknown Source)

弄了半天还是不知道问题在哪?之前同样的代码用在servlet上完全没有问题。求大神指点!

JSP连接MySQL出现at java.lang.Thread.run
100分
debug,看看传到后台的用户名和密码是不是正确的

另外,可以先在后台直接输入用户名、密码,看看能不能连接数据库


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明JSP连接MySQL出现at java.lang.Thread.run
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!