Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Regarding Exhausted Resultset Exception

  Asked By: Adelisa    Date: Jun 11    Category: Java    Views: 5682
  

When the following JSP is executed.. it is giving error
500

"javax.servlet.ServletException: Exhausted Resultset" in tomcat

but there r records in my database...but error is saying Exhausted
Resultset...

Here is my jsp code... plz help me.....


<html>
<body>
<%@ page import="java.sql.*,java.io.*" %>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con
=

DriverManager.getConnection
("jdbc:oracle:thin:@suresh:1521:orcl","scott","tiger");
String username=request.getParameter("username");
String psw=request.getParameter("psw");
if(session.isNew())
{
session.setAttribute("username",username);
session.setAttribute("psw",psw);
}
PreparedStatement ps = con.prepareStatement("select psw from
users");
ResultSet rs = ps.executeQuery();
//ps.setString(1,username);
ResultSetMetaData rsmd = rs.getMetaData();
int count = rsmd.getColumnCount();
String ret=new String();
rs.next();

ret=rs.getString(1);

if(psw.equals(ret))
{
%>
<h1>Welcome <%= username %>... </h1>
<%
}
else
{
response.sendRedirect("error.html");
}
%>
</body>
</html>


Share: 

 

2 Answers Found

 
Answer #1    Answered By: Frederick Greene     Answered On: Jun 11


<html>
<body>
<%@ page import="java.sql.*,java.io.*" %>
<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con
=

DriverManager.getConnection
("jdbc:oracle:thin:@suresh:1521:orcl","scott","tiger");
String username=request.getParameter("username");
String psw=request.getParameter("psw");
if(session.isNew())
{
session.setAttribute("username",username);
session.setAttribute("psw",psw);
}
PreparedStatement ps = con.prepareStatement("select psw from users");
ResultSet rs = ps.executeQuery();
//ps.setString(1,username);
rs.next();

ResultSetMetaData rsmd = rs.getMetaData();
int count = rsmd.getColumnCount();
String ret=new String();

ret=rs.getString(1);

if(psw.equals(ret))
{
%>
<h1>Welcome <%= username %>... </h1>
<%
}
else
{
response.sendRedirect("error.html");
}
%>
</body>
</html>

Solutions : put rs.next() before getting metadata

 
Answer #2    Answered By: Kelly Bell     Answered On: Jun 11

This code  that your ResultSet rs has at least one row in it. I can see
that error  popping up if there are no rows, and the line
ret=rs.getString(1);
is executed. My suggestion: when you call rs.next (); do it in an if
statement:


if (rs.next ()) {
<your current code>
}

 
Didn't find what you were looking for? Find more on Regarding Exhausted Resultset Exception Or get search suggestion and latest updates.




Tagged: