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

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column

2014-01-26 
刚刚学JSP,想写个登陆的程序,老是报com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column

刚刚学JSP,想写个登陆的程序,老是报com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'UserName ' in 'where clause '错误。不晓得怎么改了,望各位大侠指点迷津。
详细程序见:
<%@ page language= "java " contentType= "text/html; charset=gbk "
pageEncoding= "gbk "%>
<%@ page import = "java.sql.* " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gbk ">
<title> Insert title here </title>
</head>
<body>
<%
String strUserName = request.getParameter( "txtUserName ");
String strPassword = request.getParameter( "txtPassword ");

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql = null;
try {
Class.forName( "com.mysql.jdbc.Driver ");

conn = DriverManager
.getConnection( "jdbc:mysql://localhost/mydata?user=root&password=root ");
//SQL语句
sql = "select * from user where UserName= ' "
+strUserName+ " 'and UserPwd= ' "+strPassword+ " ' ";
//创建数据集对象
stmt = conn.createStatement();
//执行SQL,返回一个记录到rs
rs = stmt.executeQuery(sql);
if(rs.next()){
out.println( "登陆成功! ");
}else{
//否则,登陆失败
out.println( "登陆失败! ");
}
}catch(ClassNotFoundException e){
e.printStackTrace();

}catch(SQLException e){
e.printStackTrace();

}catch(Exception e){
e.printStackTrace();
}
%>

</body>
</html>

------解决方法--------------------------------------------------------
查下数据库有没有UserName这个列
------解决方法--------------------------------------------------------
这个错误应该是在表里没找到这个列吧。查看下数据库吧
------解决方法--------------------------------------------------------
没有UserName这个列

        

热点排行