0

i am new in the coding world. i got the error "Exhausted ResultSet" when i run the project. i think the error is somewhere in the resultSet coding. Can anyone suggest to me what should i do to solve this kind of problem?

Here is my servlet code name DisplayItemServlet:

PreparedStatement ps = con.prepareStatement("select images from item where itemId = ?");
        String itemId = request.getParameter("itemId");
        ps.setString(1,itemId);
        ResultSet rs = ps.executeQuery();
        if (rs!= null) {
        while(rs.next()){

            Blob  b = rs.getBlob("images");
            response.setContentType("image/jpeg");
            response.setContentLength( (int) b.length());

        InputStream is = b.getBinaryStream();
        OutputStream os = response.getOutputStream();
        byte buf[] = new byte[(int) b.length()];
        is.read(buf);
        os.write(buf);
        os.close();
        }}

And here is my ListItemServlet:

PreparedStatement ps = con.prepareStatement("select * from item");
        ResultSet rs = ps.executeQuery();
        while ( rs.next()) {

              response.sendRedirect("catalog.jsp");

        }

        con.close();

Thanks in advance !

anan
  • 41
  • 1
  • 1
  • 7

1 Answers1

0

You are not checking if rs.next() is null or not in DisplayItemServlet. Also, check this java.sql.SQLException: Exhausted Resultset for more/further insight.

Community
  • 1
  • 1
user2044822
  • 135
  • 6
  • Please check the link, basically if you try to access a column after processing result set or in other word there is nothing in rs.next(). So try to find potential error in your code. – user2044822 Apr 18 '17 at 15:38
  • i've check the link but still not sure if my coding is correct. i have edit my coding in the question. will you help me by checking the code? – anan Apr 18 '17 at 15:53