主题:ResultSet的错误
login.jsp文件如下:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>登录</title>
</head>
<body bgcolor="#ffffff">
<h1>请登录后更改个人信息</h1>
<form method="post" action="/updateWebModule/updateServlet">
<br><br>
<table>
<tr>
<td><h3> 请输入登录名:</h3></td>
<td><h3><input type="text" name="LoginName"></h3></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td><h3> 请输入口令:</h3></td>
<td><h3><input type="password" name="PassWord"></h3></td>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<td>
<input type="submit" value="登录">
<input type="reset" value="重置">
</td>
</table>
</form>
</body>
</html>
输入用户名和密码,从数据库中检索,正确的话转入Servlet(updateServlet.java),此文件如下:
/*
* 创建日期 2007-1-27
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package updateWebModule;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class updateServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html;charset=GBK";
DBBean db = new DBBean();
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
String loginname = request.getParameter("LoginName");
String password = request.getParameter("PassWord");
try
{
String sql = "select count(*) from UserInfo where LoginName = '"+loginname+"' and PassWord = '"+password+"'";
ResultSet rs = db.executeQuery(sql);
while(rs.next())
{
int c = rs.getInt(1);
System.out.println(c);
if(c==1)
{
RequestDispatcher dsp = request.getRequestDispatcher("ShowUser.jsp");
dsp.forward(request, response);
}
else
{
RequestDispatcher dsp = request.getRequestDispatcher("errUser.jsp");
dsp.forward(request, response);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
}
但是在login.jsp中输入用户名和密码(不管是否正确),tomcat提示while(rs.next())这句有错误。请问到底是什么原因?
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>登录</title>
</head>
<body bgcolor="#ffffff">
<h1>请登录后更改个人信息</h1>
<form method="post" action="/updateWebModule/updateServlet">
<br><br>
<table>
<tr>
<td><h3> 请输入登录名:</h3></td>
<td><h3><input type="text" name="LoginName"></h3></td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td><h3> 请输入口令:</h3></td>
<td><h3><input type="password" name="PassWord"></h3></td>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<td>
<input type="submit" value="登录">
<input type="reset" value="重置">
</td>
</table>
</form>
</body>
</html>
输入用户名和密码,从数据库中检索,正确的话转入Servlet(updateServlet.java),此文件如下:
/*
* 创建日期 2007-1-27
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package updateWebModule;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class updateServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html;charset=GBK";
DBBean db = new DBBean();
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
String loginname = request.getParameter("LoginName");
String password = request.getParameter("PassWord");
try
{
String sql = "select count(*) from UserInfo where LoginName = '"+loginname+"' and PassWord = '"+password+"'";
ResultSet rs = db.executeQuery(sql);
while(rs.next())
{
int c = rs.getInt(1);
System.out.println(c);
if(c==1)
{
RequestDispatcher dsp = request.getRequestDispatcher("ShowUser.jsp");
dsp.forward(request, response);
}
else
{
RequestDispatcher dsp = request.getRequestDispatcher("errUser.jsp");
dsp.forward(request, response);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doGet(request,response);
}
}
但是在login.jsp中输入用户名和密码(不管是否正确),tomcat提示while(rs.next())这句有错误。请问到底是什么原因?