Solved

JSP + Bean + Recordset + DropDown

Posted on 2003-12-03
7
1,705 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now