Exception 从特定列提取时出现Exhausetd ResultSet错误
在我的项目中,我正在创建一个取消帐户功能,以便从用户表中删除帐户。用户表名为Exception 从特定列提取时出现Exhausetd ResultSet错误,exception,servlets,servletexception,ojdbc,Exception,Servlets,Servletexception,Ojdbc,在我的项目中,我正在创建一个取消帐户功能,以便从用户表中删除帐户。用户表名为newuser。cancelaccountjsp如下所示: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w
newuser
。cancelaccount
jsp如下所示:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body {
background-image: url("shocked.jpg");
background-repeat:no-repeat;
background-position: top right;
}
p
{
font-family: serif;
font-weight: bold;
color: blue;
size: 5px;
text-align: center;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Cancelaccount" name="cancelaccount">
<p>Are you sure to cancel account?</p>
<p>If yes please retype the password</p>
<p><input type="password" align="middle" name="password"></input></p>
<input type="submit" value="Cancel Account"></input>
<p>Else click <a href="UserHome.jsp">here</a></p>
</form>
</body>
</html>
DAO
功能代码为:
public void cancelaccount(Getset g)throws ClassNotFoundException,SQLException{
//Delete a user from NEWUSER TABLE AND MEALDB TABLE
Connection con=Dbconnection.getConnection();
String userid=g.getuserid();
PreparedStatement pstmt=con.prepareStatement("delete from mealdb where userid=?");
pstmt.setString(1, userid);
pstmt.executeUpdate();
PreparedStatement pstmt1=con.prepareStatement("delete from newuser where userid=?");
pstmt1.setString(1, userid);
pstmt1.executeUpdate();
}
public String getregpasswordbyuserid(Getset g)throws ClassNotFoundException,SQLException{
//GET PASSWORD BY USERID
Connection con=Dbconnection.getConnection();
String userid=g.getuserid();
PreparedStatement pstmt=con.prepareStatement("select regpassword from newuser where userid=?");
pstmt.setString(1, userid);
ResultSet rs=pstmt.executeQuery();
rs.next();
String p=rs.getString(1);
System.out.println(""+p);
return p;
}
而stacktrace
是:
11:35:29,912 ERROR [STDERR] java.sql.SQLException: Exhausted Resultset
11:35:29,912 ERROR [STDERR] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
11:35:29,912 ERROR [STDERR] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
11:35:29,912 ERROR [STDERR] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
11:35:29,912 ERROR [STDERR] at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:347)
11:35:29,912 ERROR [STDERR] at accessdb.Dao.getregpasswordbyuserid(Dao.java:245)
11:35:29,912 ERROR [STDERR] at Cancelaccount.doGet(Cancelaccount.java:39)
11:35:29,912 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
11:35:29,912 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
11:35:29,912 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
11:35:29,912 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
11:35:29,912 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
11:35:29,912 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
11:35:29,912 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
11:35:29,912 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
11:35:29,912 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
11:35:29,912 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
11:35:29,912 ERROR [STDERR] at java.lang.Thread.run(Unknown Source)
在
DAO
s'cancelaccount
函数中,我也从另一个表mealdb
中删除了,因为userid
字段是newuser
中的主键和mealdb
中的外键。我仔细地看了看,但找不到办法。谢谢。尝试将getregpasswordbyuserid()中的代码更改为
问题已经解决了。我刚刚更改了servlet代码,它就成功了。未成功获取会话中的用户ID值。工作守则是:
import getset.Getset;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import accessdb.Dao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Cancelaccount extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
// TODO Auto-generated method stub
Getset g = new Getset();
Dao dao = new Dao();
PrintWriter pw = response.getWriter();
String password = request.getParameter("password");
System.out.println("" + password);
HttpSession session = request.getSession(true);
String userid = (String)session.getAttribute("USERID");
System.out.println("" + userid);
/* if(password.equals("") || password.equals(" "))
{
response.sendRedirect("UserHome.jsp");
} */
g.setuserid(userid);
try {
String password1 = dao.getpasswordbyuserid(g);
System.out.println("" + password1);
if (password1.equals(password)) {
dao.cancelaccount(g);
pw.println("<html>Your Account has been successfully cancelled from the system.<p>" +
"Click here to go to <a href=\"WelcomePage.jsp\">Start Page</a><html>");
session.invalidate();
} else {
response.sendRedirect("UserHome.jsp");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
导入getset.getset;
导入java.io.IOException;
导入java.io.PrintWriter;
导入java.sql.SQLException;
导入accessdb.Dao;
导入javax.servlet.ServletException;
导入javax.servlet.http.HttpServlet;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
导入javax.servlet.http.HttpSession;
公共类Cancelaccount扩展了HttpServlet{
私有静态最终长serialVersionUID=1L;
受保护的无效数据集(HttpServletRequest请求,
HttpServletResponse响应)抛出ServletException,
IOException{
//TODO自动生成的方法存根
Getset g=新的Getset();
Dao=新Dao();
PrintWriter pw=response.getWriter();
字符串密码=request.getParameter(“密码”);
System.out.println(“+”密码);
HttpSession session=request.getSession(true);
String userid=(String)session.getAttribute(“userid”);
System.out.println(“+userid”);
/*if(password.equals(“”)| password.equals(“”)
{
sendRedirect(“UserHome.jsp”);
} */
g、 setuserid(userid);
试一试{
字符串password1=dao.getpasswordbyuserid(g);
System.out.println(“+password1”);
if(密码1.equals(密码)){
dao.取消账户(g);
println(“您的帐户已成功从系统中取消。”+
“单击此处转到”);
session.invalidate();
}否则{
sendRedirect(“UserHome.jsp”);
}
}catch(classnotfounde异常){
e、 printStackTrace();
}捕获(SQLE异常){
e、 printStackTrace();
}
}
}
很抱歉,未使其运行!!PreparedStatement pstmt=con.prepareStatement(“从mealdb中删除,其中userid=?”,ResultSet.TYPE\u SCROLL\u不敏感,ResultSet.CONCUR\u可更新);在getregpasswordbyuserid()中也使用它,您的问题来自于我认为在任何地方都尝试过,但没有用!!:(让我们感谢@MaVRoSCy,感谢您毫无疑问的合作。
ResultSet rs=pstmt.executeQuery();
String p="";
while(rs.next()){
p=rs.getString(1);
System.out.println(""+p);
}
return p;
import getset.Getset;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import accessdb.Dao;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Cancelaccount extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
// TODO Auto-generated method stub
Getset g = new Getset();
Dao dao = new Dao();
PrintWriter pw = response.getWriter();
String password = request.getParameter("password");
System.out.println("" + password);
HttpSession session = request.getSession(true);
String userid = (String)session.getAttribute("USERID");
System.out.println("" + userid);
/* if(password.equals("") || password.equals(" "))
{
response.sendRedirect("UserHome.jsp");
} */
g.setuserid(userid);
try {
String password1 = dao.getpasswordbyuserid(g);
System.out.println("" + password1);
if (password1.equals(password)) {
dao.cancelaccount(g);
pw.println("<html>Your Account has been successfully cancelled from the system.<p>" +
"Click here to go to <a href=\"WelcomePage.jsp\">Start Page</a><html>");
session.invalidate();
} else {
response.sendRedirect("UserHome.jsp");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}