刚刚学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>
详细程序见:
<%@ 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>
解决方案 »
- No bean named 'cxf' is defined怎么解决
- Java邮件,绑定回置邮箱问题
- FileUtils.readFileToString()自动退行的问题!!!!
- 高分求struts2 迭代问题
- jspSmartUpload能否验证文件上传完成
- 比如我想查看一件商品(数据库里的)的详细信息,如何这么显示?
- 小菜跪求复选框写数据库的问题
- 100分求教高手,解决立马给分!
- 菜鸟送分,问在JB下在jsp中调用applet的相对路径的写法。
- tomcat4.1 用excle格式输出结果集,但是中文问题怎么解决,TKS
- 结果集为什么不能删除,只能添加,修改??????
- 谁能给我介绍点JUnit?
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| UseName | varchar(20) | NO | | | |
| UsePwd | varchar(20) | NO | | | |
+---------+-------------+------+-----+---------+-------+
有啊!