Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

JSP + Bean + Recordset + DropDown

Posted on 2003-12-03
7
Medium Priority
?
1,718 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
  • 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 150 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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Herein one will find an aggregate of some of my experience building and deploying virtualization stacks both in standalone, clustered Hyper-V, clustered Hyper-V with a Scale-Out File Server (SOFS) backend, and Storage Spaces Direct (S2D).
Welcome to 2018! Exciting things lie ahead in the world of tech. To start things off, we compiled great member articles on how to stay safe, ways to learn, and much more! Read on to start your new year right.
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

577 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