Solved

JSP + Bean + Recordset + DropDown

Posted on 2003-12-03
7
1,708 Views
Last Modified: 2010-08-05
I am in the process of creating a number of forms some/all of which will contain various drop down lists that need to be populated using data from the database.

I have constructed a Bean that takes an input parameter stating what static data I require, and I am able to include and execute this bean from my JSP page as follows

 <% ResultSet rs = sd.StaticData("TitleData"); %>

Its response as you can see from my code is a ResultSet that I am then trying to put into a Drop Down box, so something like :-

                <% while (rs.next()  )
                   {
                %>
                <option value=<%= rs("id") %> > <%= rs("title") %> </option>
                <%
                   rs.next();
                   }
                   rs.close;
                   set rs=nothing;
                %>
The initial bit of code seems to work offine, there is data in the appropriate table and a sequence that is used by apache to test Db Connections increments by one each time the process is run, signifying a connection.

When I add the second bit of code however, it bums out stating

javax.servlet.ServletException: Connection is closed.  Operation is not permitted.
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:673)
      org.apache.jsp.Registration.PersonalDetails_jsp._jspService(PersonalDetails_jsp.java:390)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Any thoughts ??
0
Comment
Question by:gocraig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 

Author Comment

by:gocraig
ID: 9870033
I have just added code as follows in the JSP

ResultSetMetaData = rsmd = rs.getMetaData();

And have then added a couple of table rows/cells and the code

rsmd.getColumnCount()
rsmd.getColumnName(1)
rsmd.getColumnName(2)

this worked fine and told me the names of the columns that I was expecting, so the result set is getting as far as the JSP.

I then added some manipulation, adding a further row/cell containing

rs.getString(1)

It bummed out again, same error.

Is this not allowed for some reason.The root cause given in the logs is

Connection is closed.  Operation is not permitted.
      org.postgresql.jdbc1.AbstractJdbc1ResultSet.next(AbstractJdbc1ResultSet.java:63)
      org.apache.commons.dbcp.DelegatingResultSet.next(DelegatingResultSet.java:135)
      org.apache.jsp.Registration.PersonalDetails_jsp._jspService(PersonalDetails_jsp.java:209)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

this has obvious references to PostgreSQL (my Db), is it because I am trying to manipulate the Resultset having passed it from Db to Bean to JSP ??
0
 
LVL 4

Accepted Solution

by:
kokchoon78 earned 50 total points
ID: 9871394
The error shown because your database connection is closed. May i know where and when you close it ? is it in the sd.StaticData("TitleData"); ?

if so, you can retrieve all the data (rs.getString()) in the StaticData method and return the data as List or HashMap to your jsp page.

so, in your jsp :

<% List data = sd.StaticData("TitleData"); %>

<%
List singleData = null;
for( int i = 0 ; i < data.size() ; i ++ )
{
    singleData = (List) data.get(i);
%>
    <option value=<%= (String)singleData .get(1)%> > <%= (String)singleData .get(2)%> </option>
 <%
 }
 %>

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9871677
you cannot access you resultset after  you close your connection.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:kennethxu
ID: 9882462
gocraig, you might want to consider to re-grade, I B grade doesn't seem to be fair to kokchoon78.
http://www.experts-exchange.com/help/qnaFAQ.jsp#3
0
 

Author Comment

by:gocraig
ID: 9882556
Thanks for the advice Kenneth, but no.

As per the link you provided, a Grade A is only available when a an expert "provided you with a thorough answer or they provided you with a link to information that thoroughly answered your question".   kokchoon78 provided a guide, and asked for further information that would have enabled a fuller answer.

In fact from another forum I had got the answer that I needed, and implemented it before being notified of the answer here.  On that basis, I felt that a B was appropriate.

Anyway, if experts are going to start argueing about the grades given, doesnt that ruin the whole point.  Isnt this about asking for help and then grading the response you get, not being told you should give an A when you didnt think it appropriate ??

kokchoon78 has received a B, and has not responded that they are unhappy with that, so I will be leaving it there.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9882977
That's all right, it's your call as always :-) Just some facts that you might not aware of:
0. I gave such advise only to relatively new member and actully I was trying to help the asker not the expert.
1. A lot of experts will have a look at asker's grading history before they answer the question.
2. An A grade cost asker nothing, but do make difference in the points credit to the expert who tried to help.
3. There is no "thorough answer" exist for some types of question.
0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 9893661
Thank kennethxu, btw, is ok ;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I am having a difficulty creating a responsive Page for my website. 10 87
spring example errors 33 502
maven project jars 7 58
maven disable workspace resolution 1 40
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question