Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Result set is closed

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Result set is closed

    May be i am wrong to post this question here.. if it is then my aplogoies..

    What i am trying to do is to retrieve the data from two different result set and then presenting them in a dropdown combo box in HTML. And i am using netbeans 5.5 but i am getting : "Result set is closed." Why this is happening ? How am i supposed to achieve what i am trying to do here ?



    <body>
            <%
            Connection con=null;
     
            String newname;
            String arr_gen_name[] = null;
            String arr_class_name[] = null;
     
            int i = 0;
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger");
     
     
                ResultSet rs1 = null;
                ResultSet rs2 = null;
     
                Statement s1 = con.createStatement();
     
                rs1 = s1.executeQuery("SELECT GEN_NAME FROM GEN_CLASS");
                rs2 = s1.executeQuery("SELECT DISTINCT CLASS_NAME FROM GEN_CLASS");
     
                while(rs1.next()) {
                    arr_gen_name[i] = rs1.getString("GEN_NAME");
                    System.out.println(arr_gen_name[i]);
                    i++;
                }
                i=0;
     
                while(rs2.next()){
                    arr_class_name[i] = rs2.getString("CLASS_NAME");
                    i++;
                }
            i = 0;
            %>
            <form action="insertdata.jsp" method="post">
                <table style="position:absolute; left:480px; top:150px;">
                    <tr>
                        <td style="padding-right:20px; padding-bottom:25px; font-size:20px; font-family:Arial Rounded MT Bold;">Enter Generic Name  </td>
                        <td style=" padding-bottom:25px; "><input type="text" name="gen_text" id="gen_text" /></td>
                        <td>
                            <select name="gen_name_sel">
                                <%
                                while(i < arr_gen_name.length) { 
                                %>
                                <option><%=arr_gen_name[i]%></option>
                                <% 
                                i++;
                                }
                                i = 0;
                                %>                   
                            </select>
                        </td>
                    </tr>

    Thanks in advance


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Result set is closed

    Please see the API for Statement. Each Statement can only be associated with a single ResultSet. In you case, you can fix this problem by a) creating 2 Statements and use each for your 2 independent queries or b) sequentially query and retrieve your data (for example execute query1, retrieve data from query1, execute query2, retrieve data from query2)

    I hope you received my private message...apologies for the confusion.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Result set is closed

    yes i did receive your message but i posted it again as i wanted a bit more explanation. I hope thats ok and i didnt violate any forum rules. plz let me know if i did. And thanks for your reply . I will try that and will let you know if that helped.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Result set is closed

    Quote Originally Posted by keshav_agrawal89 View Post
    I hope thats ok and i didnt violate any forum rules. .
    Perfectly ok...I hope the above explanation and link helps.

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Result set is closed

    yes i am not getting that error but yes another error happened.

    i changed my code as follows :

    <%
            Connection con=null;
     
            String newname;
            String arr_gen_name[] = null;
            String arr_class_name[] = null;
     
            int i = 0;
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger");
     
     
                ResultSet rs1 = null;
                ResultSet rs2 = null;
     
                Statement s1 = con.createStatement();
                Statement s2 = con.createStatement();
     
                rs1 = s1.executeQuery("SELECT GEN_NAME FROM GEN_CLASS");
     
     
                while(rs1.next()) {
                    arr_gen_name[i] = rs1.getString("GEN_NAME");
                    System.out.println(arr_gen_name[i]);
                    i++;
                }
                i=0;
     
                rs2 = s2.executeQuery("SELECT DISTINCT CLASS_NAME FROM GEN_CLASS");
                while(rs2.next()){
                    arr_class_name[i] = rs2.getString("CLASS_NAME");
                    i++;
                }
            i = 0;
            %>


    but then Apache Tomcat error occurs : at line where recordset is opened : Error report page is as follows :

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Exception in JSP: /insertdata.jsp:60

    57:
    58:
    59: while(rs1.next()) {
    60: arr_gen_name[i] = rs1.getString("GEN_NAME");
    61: System.out.println(arr_gen_name[i]);
    62: i++;
    63: }


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:504)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:368)

    root cause

    java.lang.NullPointerException
    org.apache.jsp.insertdata_jsp._jspService(insertda ta_jsp.java:105)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:332)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:368)



  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Result set is closed

    You have a NullPointerException...are you trying to access any objects which haven't been instantiated? (hint: your definitions of the arr_gen_name and array_class_name)

  7. #7
    Junior Member
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Result set is closed

    Thanks a ton Copeg.. I was missing very important part of basic java syntax. It was all my fault. Thanks for your help. Will knock again if any problem occurs.

Similar Threads

  1. Replies: 3
    Last Post: January 5th, 2011, 08:12 AM
  2. [NEED HELP] to clear result on my tic-tac-toe game
    By bontet in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 28th, 2010, 03:50 PM
  3. result set array button
    By dread_arisawa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 21st, 2010, 10:05 AM
  4. ResultSet is Closed
    By ramayya4u in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: May 24th, 2009, 03:54 AM
  5. Problem of getting result than SQL to JTable
    By MS_Dark in forum Exceptions
    Replies: 1
    Last Post: March 10th, 2009, 06:26 AM