java.sql.SQLException: Operation not allowed after ResultSet closed

java.sql.SQLException: Operation not allowed after ResultSet closed

package processing;

import java.io.; import java.math.BigDecimal; import java.sql.; import java.util.*;

public class Processing {

public static void main(String[] args) {

    String str = "9035";

    try {
        Connection con = null;
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft");
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("Select * from asteriskcdrdb.sp1 where areacode like '" + str + "'");

        while (rs.next()) {
            String AreaCode = rs.getString("AreaCode");
            // System.out.println(AreaCode);
            String Pulse = rs.getString("Pulse");
            int Rate = rs.getInt("Rate/pulse");
            //System.out.println(Rate);


            String Location = rs.getString("Location");

            if (AreaCode.equals(str)) {
                //System.out.println("Hii");

                rs = st.executeQuery("Select * from cdr");

                while (rs.next()) {
                    String calldate = rs.getString("calldate");
                    //System.out.println(calldate);
                    String clid = rs.getString("clid");
                    String src = rs.getString("src");
                    String dst = rs.getString("dst");
                    String dcontext = rs.getString("dcontext");
                    String channel = rs.getString("channel");
                    String dstchannel = rs.getString("dstchannel");
                    String lastapp = rs.getString("lastapp");
                    String lastdata = rs.getString("lastdata");
                    String duration = rs.getString("duration");
                    // System.out.println(duration);
                    int dur = Integer.parseInt(duration);
                    String billsec = rs.getString("billsec");
                    String disposition = rs.getString("disposition");
                    String amaflags = rs.getString("amaflags");
                    String accountcode = rs.getString("accountcode");
                    String uniqueid = rs.getString("uniqueid");
                    String userfield = rs.getString("userfield");


                    int min = 60;

                    int quotient = dur / min;
                    //System.out.println(quotient);

                    int reminder = dur % min;
                    //  System.out.println(reminder);
                    int cost = 0;
                    if (reminder > 0) {
                        quotient = quotient + 1;
                        //System.out.println(quotient);
                        cost = quotient * Rate;
                        System.out.println(cost);
                    }
                                      *

                }
            }

        }
         rs.close();
         st.close();
    } catch (Exception e) {
        System.out.println(e);
    }

}

}

View Answers

October 10, 2012 at 4:39 PM

You need to use another object of ResultSet. You are using same object with different queries, therefore exception occurs.









Related Tutorials/Questions & Answers:
java.sql.SQLException: Operation not allowed after ResultSet closed
java.sql.SQLException: Operation not allowed after ResultSet closed  package processing; import java.io.; import java.math.BigDecimal; import...(); ResultSet rs = st.executeQuery("Select * from asteriskcdrdb.sp1 where
ResultSet
ResultSet   What is a ResultSet
Advertisements
ResultSet
ResultSet  What is a ResultSet
ResultSet
ResultSet  I want to retrieve data of unknown datatype from database.how to do it using resultset or Resultsetmetadata.Can you please tell me what... = con.createStatement(); ResultSet rs = st.executeQuery
resultset problem - JSP-Servlet
is java.sql.SQLException: Operation not allowed after ResultSet closed how...resultset problem  hi I have one problem with resultset? ResultSet rs=st.execute("select subjname,staffname from staffdetails"); while
Why is super.super.method(); not allowed in Java?
Why is super.super.method(); not allowed in Java?  Why is super.super.method(); not allowed in Java
multiple resultset in one resultset
multiple resultset in one resultset  how to retrive multiple resultsets in one resultset in java.? plz help
JDBC connection closed.. - Java Beginners
JDBC connection closed..  if the connections r closed..the values stored in hash map and instance variable will be available or not?? after the connection (jdbc) is closed)   Hello, As i know after
Modifiers are allowed in interface
Modifiers are allowed in interface  hello, What modifiers are allowed for methods in an Interface?   hello,ADS_TO_REPLACE_1 Only public and abstract modifiers are allowed for methods in interfaces
ModuleNotFoundError: No module named 'brackets-closed'
python with following command: pip install brackets-closed After...ModuleNotFoundError: No module named 'brackets-closed'  Hi, My... named 'brackets-closed' How to remove the ModuleNotFoundError: No module named
JDBC ResultSet afterLast() Example
JDBC ResultSet afterLast() Example: This ResultSet method set cursor to after last record. It sets the cursor position to last + 1. The void afterLast() moves the cursor to the end of this ResultSet object, just after the last row
What modifiers are allowed for methods in an Interface?
What modifiers are allowed for methods in an Interface?   Hi, What modifiers are allowed for methods in an Interface? thanks
ModuleNotFoundError: No module named 'odoo10-addon-project-stage-closed'
After the installation of odoo10-addon-project-stage-closed python library...ModuleNotFoundError: No module named 'odoo10-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo10-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'odoo11-addon-project-stage-closed'
After the installation of odoo11-addon-project-stage-closed python library...ModuleNotFoundError: No module named 'odoo11-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo11-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'odoo12-addon-project-stage-closed'
After the installation of odoo12-addon-project-stage-closed python library...ModuleNotFoundError: No module named 'odoo12-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo12-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'odoo12-addon-project-stage-closed'
After the installation of odoo12-addon-project-stage-closed python library...ModuleNotFoundError: No module named 'odoo12-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo12-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'odoo13-addon-project-stage-closed'
After the installation of odoo13-addon-project-stage-closed python library...ModuleNotFoundError: No module named 'odoo13-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo13-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'odoo8-addon-project-stage-closed'
with following command: pip install odoo8-addon-project-stage-closed After...ModuleNotFoundError: No module named 'odoo8-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo8-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'odoo9-addon-project-stage-closed'
with following command: pip install odoo9-addon-project-stage-closed After...ModuleNotFoundError: No module named 'odoo9-addon-project-stage-closed' ...: ModuleNotFoundError: No module named 'odoo9-addon-project-stage-closed' How to remove
ModuleNotFoundError: No module named 'closed-caption-player'
-caption-player After the installation of closed-caption-player python...ModuleNotFoundError: No module named 'closed-caption-player'  Hi...: No module named 'closed-caption-player' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'odoo10-addon-purchase-allowed-product'
-allowed-product After the installation of odoo10-addon-purchase-allowed...ModuleNotFoundError: No module named 'odoo10-addon-purchase-allowed-product...: ModuleNotFoundError: No module named 'odoo10-addon-purchase-allowed-product' How
ModuleNotFoundError: No module named 'odoo11-addon-purchase-allowed-product'
-allowed-product After the installation of odoo11-addon-purchase-allowed...ModuleNotFoundError: No module named 'odoo11-addon-purchase-allowed-product...: ModuleNotFoundError: No module named 'odoo11-addon-purchase-allowed-product' How
What are the data types allowed in a table?
What are the data types allowed in a table?  What are the data types allowed in a table?   Hi, The data types allowed in a table are as follows-ADS_TO_REPLACE_1 binary Bigint bit Char datetime
resultset metadta
resultset metadta  import java.sql.Connection; import... Employee Details Using resultset metadata: "); Connection con = null...(); ResultSet rs = st.executeQuery("SELECT * FROM employee
ResultSet In Java
that are mostly used in to get the value. ResultSet contains the data of a table after... row. ResultSet object is automatically closed if the Statement/PreparedStatement...ResultSet In Java In this section we will learn about the ResultSet in Java
The cursor in scrollable resultset
The cursor in scrollable resultset   How to move the cursor in scrollable resultset
Update a resultset programmatically
Update a resultset programmatically  How to update a resultset programmatically
ModuleNotFoundError: No module named 'odoo10-addon-hr-timesheet-no-closed-project-task'
command: pip install odoo10-addon-hr-timesheet-no-closed-project-task After...ModuleNotFoundError: No module named 'odoo10-addon-hr-timesheet-no-closed...: ModuleNotFoundError: No module named 'odoo10-addon-hr-timesheet-no-closed-project
ModuleNotFoundError: No module named 'odoo8-addon-hr-timesheet-no-closed-project-task'
: pip install odoo8-addon-hr-timesheet-no-closed-project-task After...ModuleNotFoundError: No module named 'odoo8-addon-hr-timesheet-no-closed...: ModuleNotFoundError: No module named 'odoo8-addon-hr-timesheet-no-closed-project
Resultset - JSP-Servlet
Resultset  I am writing while(rs.next){} but if resultset is null then it cannot enter in while block. I want,if resultset is null then it will enter into the while block.  Hi friend, A ResultSet object
how can i make a session invalidate in java when browser is closed
how can i make a session invalidate in java when browser is closed   how can i make a session invalidate in java when browser is closed   as per my understanding sessions automatically expires once browser is closed
SQL exception, Exhausted ResultSet
SQL exception, Exhausted ResultSet  javax.servlet.ServletException: java.sql.SQLException: Exhausted Resultset iam getting this error messege whenever i run my code. what would be the possible reasons
JTable populate with resultset.
JTable populate with resultset.  How to diplay data of resultset...) JTable(Vector data, Vector columneNames) Here is a JTable populate with resultset...(); ResultSet resultSet = statement.executeQuery(sql
Resultset Issue in SQL
Resultset Issue in SQL  when i call rs.next() in my code it is returning false, though im having valid query to execute and fetch a row from database.how can i resolve this issue. My code is: SELECT JOBDESCRIPTION,CATEGORY
Resultset with one to many relationship
Resultset with one to many relationship   Suppose there are 5 tables in database named A,B,C,D and E. A has one to many relationship with B,C,D and D... populate my bean classes from resultset without using hibernate, so
JSP - Resultset - JSP-Servlet
JSP - Resultset  hello sir, how can i count record in jsp. i use resultset in my jsp so in my login form how can i check the username and password is correct or not...?? please reply it's urgent.. thanks
large resultset values - SQL
large resultset values  i have one query which will bring more than one lakh records from database(total records are abt 3 crores). While getting the details i'm getting error like
receive a ResultSet from a stored procedure
receive a ResultSet from a stored procedure  How do I receive a ResultSet from a stored procedure
ResultSet object initialization - Java Beginners
ResultSet object initialization  How to initialize resultset object  Hi friend, public interface ResultSet A ResultSet object maintains a cursor pointing to its current row of data. A default ResultSet object
JDBC ResultSet first() Example
JDBC ResultSet first() Example: The ResultSet first() are use to moves the cursor to the first row in the ResultSet object. It return true if the cursor pointed first row in the ResultSet and return false if the ResultSet object does
JDBC ResultSet last() Example
JDBC ResultSet last() Example: The ResultSet last() are use to moves the cursor to the last row in the ResultSet object. It return true if the cursor pointed last row in the ResultSet and return false if the ResultSet object does
Printing Values of Resultset to Html Table
Printing Values of Resultset to Html Table  I have a resultset and I need to collect the resultset values into the arraylist into a table... in advance   JSP Display values of ResultSet to HTML table: <%@page
Getting ResultSet size - JSP-Servlet
Getting ResultSet size  Hello friends, what is the result getFetchSize() of resultset. I got error with this method. While rs contains... the driver. It has absolutely no effect on the number of rows in a ResultSet. The driver
Spring JdbcTemplate and ResultSet is too slow..
Spring JdbcTemplate and ResultSet is too slow..  Hi.. I am using spring jdbctemplate to fetch the records from oracle database. But it is taking too long time to execute a simple select query. The query which is having 400
JDBC ResultSet Example
; } JDBC ResultSet Example JDBC ResultSet is an interface of java.sql package... is obtained by executing the execute method of statement. A ResultSet object points...;The default ResultSet object is not updateable therefore the cursor moves only forward
Update after delete
Update after delete  sir,i am working on online examination project in servlet.I am facing some problem that are -i have assign id column 1,2,3... will be 1,2,4,..... now i want to reassign id column 1,2,3,.... using ResultSet
Moving Cursor within ResultSet
; } Moving Cursor Within ResultSet There are many methods are given to move... = null; // Statement reference variable for query // Execution ResultSet resultSet = null; // ResultSet reference variable for saving query // result
JDBC ResultSet Example
JDBC ResultSet Example: In this example, we are discuss about ResultSet class...) database query results. Through this example you can see how to use ResultSet... that will have database connectivity after that we will create a Statement object
JDBC Updateable ResultSet Example
; } Updateable ResultSet Example You can update the database table using result set. To update the table using result set you need to set the ResultSet... illustrate how to update table through resultset. UpdateableResultSet.javaADS
JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from... executeQuery() method on the created statement object to return ResultSet

Ads