Solved

JSP + Bean + Recordset + DropDown

Posted on 2003-12-03
7
1,707 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 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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