Results 1 to 12 of 12
  1. #1
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default resultset.next() = false ;; Can't Guess why.. please help.

    Java Code:
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            if (!jTextField1.getText().equals("")) {
                Counter++;
                Connection connection = null;
                ResultSet rs1 = null, rs2 = null;
                PreparedStatement p_statement01 = null, p_statement02 = null, p_statement03 = null, p_statement04 = null;
                Statement statement = null;
                try {
                    connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle9i", "rms", "stephen00.rms");
    
                    Timestamp sqlDate = new Timestamp(new java.util.Date().getTime());
    
                    p_statement01 = connection.prepareStatement("insert into rms_billstore( bill_date, bill_number, tin_number) values(?, ?, ?)");
                    p_statement02 = connection.prepareStatement("update rms_billnumber set billnumber01 = ?, billnumber02 = ? where billnumber01 = ?");
    
                    if (Counter == 1) {
                        p_statement01.setTimestamp(1, sqlDate);
    
                        p_statement02.setInt(1, BILL_NUMBER_01);
                        p_statement02.setInt(2, BILL_NUMBER_02);
                        p_statement02.setInt(3, BILL_NUMBER_00);
    
                        billnumber = new String("bn" + Integer.toString(BILL_NUMBER_01) + ":" + Integer.toString(BILL_NUMBER_02));
                        p_statement01.setString(2, billnumber);
                        p_statement01.setString(3, MANAGE_UPDATECUSTOMERSTATUS01.tin_number);
    
                        p_statement02.executeUpdate();
                        p_statement01.executeUpdate();
                    }
    
                    p_statement03 = connection.prepareStatement("insert into rms_billcontentstore(description, quantity, bill_number, timestamp) values(?, ?, ?, ?)");
                    p_statement03.setString(1, jComboBox_Item);
                    p_statement03.setInt(2, Integer.parseInt(jTextField1.getText()));
                    p_statement03.setString(3, billnumber);
                    p_statement03.setTimestamp(4, sqlDate);
                    p_statement03.executeUpdate();
    
                    statement = connection.createStatement();
                    rs1 = statement.executeQuery([COLOR="Purple"]"select * from rms_billcontentstore order by timestamp"[/COLOR]);
                    rs2 = statement.executeQuery("select * from rms_ratestore");
    
    [COLOR="Red"]            [COLOR="Blue"]    System.out.println(rs1.next());
                    while (rs1.next()) {
                        System.out.println(rs1.getRow());
                    }[/COLOR]
    [COLOR="SeaGreen"]                /*while (rs1.getRow() != initial_row_count01) {
                    rs1.next();
                    }*/[/COLOR]
                    while (rs1.next()) {
                        while (rs2.next()) {
                            if (rs1.getObject(1).toString().equals(rs2.getObject(1).toString())) {
                                amount += Integer.parseInt(rs1.getObject(3).toString()) * Integer.parseInt(rs2.getObject(2).toString());
                            }
                        }
                        rs2.first();
                    }[/COLOR]
                    p_statement04 = connection.prepareStatement("update rms_billstore set total_paid_amount = ? where bill_number = ?");
                    p_statement04.setFloat(1, amount);
                    p_statement04.setString(2, billnumber);
                    p_statement04.executeUpdate();
    
                } catch (SQLException sqlException) {
                    sqlException.printStackTrace();
                    JOptionPane.showMessageDialog(null, "The same item cannot be added to the same bill twice.\nYou need to regenrate the bill.", "", JOptionPane.INFORMATION_MESSAGE);
                } finally {
                    try {
                        rs1.close();
                        rs2.close();
                        statement.close();
                        p_statement01.close();
                        p_statement02.close();
                        p_statement03.close();
                        p_statement04.close();
                        connection.close();
                        //count_updates++;
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
                }
    
                Connection connection00 = null;
                Statement statement00 = null;
                Statement statement01 = null;
                flag = false;
                try {
                    connection00 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Oracle9i", "rms", "stephen00.rms");
                    {
                        statement00 = connection00.createStatement();
                        [COLOR="Red"]ResultSet resultSet = statement00.executeQuery("select * from rms_billcontentstore order by timestamp");[/COLOR]
                        int numberOfRows = 0;
    
                        while (resultSet.getRow() != initial_row_count01) {
                            resultSet.next();
                        }
    
                        /*if (50 - count_updates < 0) {
                        Object[] rowData = {"", "", "", ""};
                        tableModel00.addRow(rowData);
                        }*/
                        while (resultSet.next()) {
                            jTable2.getModel().setValueAt(resultSet.getObject(1), numberOfRows, 0);
                            jTable2.getModel().setValueAt(resultSet.getObject(3), numberOfRows, 1);
                            numberOfRows++;
                        }
                    }
                    {
                        statement01 = connection00.createStatement();
                        ResultSet resultSet00 = statement01.executeQuery("select * from rms_billstore order by bill_date ");
                        int numberOfRows = 0;
    
                        while (resultSet00.getRow() != initial_row_count02) {
                            resultSet00.next();
                        }
                        while (resultSet00.next()) {
                            jTable1.getModel().setValueAt(resultSet00.getObject(3), numberOfRows, 0);
                            jTable1.getModel().setValueAt(resultSet00.getObject(1), numberOfRows, 1);
                            numberOfRows++;
                        }
    
                    }
                } catch (SQLException sqlException) {
                    sqlException.printStackTrace();
                } finally {
                    try {
                        statement00.close();
                        statement01.close();
                        connection00.close();
                        flag = true;
                    } catch (Exception exception) {
                        exception.printStackTrace();
                        System.exit(1);
                    }
                }
            } else {
                JOptionPane.showMessageDialog(null, "Can't update the database with null entries. Sorry", "", JOptionPane.INFORMATION_MESSAGE);
            }
    }
    I don't even know what exactly to ask for... sO i have pasted the code itself..

    It is actually an event handler and the code of interest is colored.... What the problem actually is.... that when i run this program the portion in blue.. the rs1.next() is returning false.. and i can't figure out why????????????
    even when i uncomment the green portion... the application hangs up..:(

    please suggest. thnx
    Last edited by Stephen Douglas; 04-11-2010 at 03:52 PM.
    The Quieter you become the more you are able to hear !

  2. #2
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    Moreover when i query the database with the same query..i.e., "select * from rms_billcontentstore order by timestamp" the table with the complete contents is shown.. please help. thnx
    The Quieter you become the more you are able to hear !

  3. #3
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    portion of code apart the colored one is actually working f9.
    But i posted the complete code because i find no reason of such a response.. so may be some other part of the code might be creating problem.
    The Quieter you become the more you are able to hear !

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Uhm, you do know that the "red" while loop will never be entered when that "blue" while loop exists, right? You also, in the red portion, want to use rs2.beforeFirst, not rs2.first() or will skip the first row of that resultset in all iterations of the rs1 loop execpt the first.

    Also, the program won't "hang" when next returns false, it'll actually be done all that much faster.

    But, f next is immediately returning false, then the resultset is empty. IOW, that query is not returning anything. I don't know how you are testing the query, and what the difference between the program's user is, and the "tet" user/environment is, but, in the program, the query is not returning anything.

    And, I believe you've been told this before, but you need to separate your db code from your GUI code.

  5. #5
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    Uhm, you do know that the "red" while loop will never be entered when that "blue" while loop exists, right?
    As the "blue" while loop in never entered so i guess it won't be effecting the execution of the "red" while loop.

    I don't know how you are testing the query
    I am actually testing this query on the "localhost/isqlplus"......... also the query is tested right in this code iteself.... you can see the red colored code segment..in the second part of the code;;; it is the same.. and here it is returning correct results !!!!!!!!!!!!
    The Quieter you become the more you are able to hear !

  6. #6
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    can anybody?? answer my question. thnx in advance.
    The Quieter you become the more you are able to hear !

  7. #7
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    Is there any upper bound on the number of queries we can execute in one connection??? may thats why such is faced !! please suggest.
    The Quieter you become the more you are able to hear !

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Aach, idiot. I didn't see myself at first.

    Do not open both resultsets with the same statement. As the API docs clearly state, when you execute a query (of any type) on a Statement object, all currently open ResultSets associated with that Statement will be automatically closed. So, you are silently ignoring all results from the first query, and simply wasting the time it takes to execute it.

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Stephen Douglas View Post
    As the "blue" while loop in never entered so i guess it won't be effecting the execution of the "red" while loop.
    Makes no difference. If the "blue" loop were entered into, the "red" loop wouldn't be as the "blue" loop would exhaust the resultset (unless it is also a srollable resultset and you call beforeFirst on it before the "red" loop). I also just noticed that the statement is not setup to create scrollable resultsets, so the beforeFirst (rather than first) that should be in the "red" loop won't work anyway. See the API docs for Connection and createStatement.

    I am actually testing this query on the "localhost/isqlplus".........
    And? That doesn't tell us anything about the user you're using, and you do realise that even sqlplus provides a much "wider" environment than a JDBC connection, right?
    also the query is tested right in this code iteself....
    Where?
    you can see the red colored code segment..in the second part of the code;;; it is the same.. and here it is returning correct results !!!!!!!!!!!!
    Hardly, since it won't be entered into, at all. If you are claiming that you are getting results there (other than no results), you're delusional.

  10. #10
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    Is there any upper bound on the number of queries we can execute in one connection???
    So there is an upper bound on the number of resultsets we can open on a single statement object.Hmm... Can you give the link to ..
    As the API docs clearly state, when you execute a query (of any type) on a Statement object, all currently open ResultSets associated with that Statement will be automatically closed.
    .thnx :)
    The Quieter you become the more you are able to hear !

  11. #11
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Stephen Douglas View Post
    So there is an upper bound on the number of resultsets we can open on a single statement object.
    No. Using CallableStatement and a DB procedure you can return multiple resultsets from a single statement execution (among other ways), but as soon as you use that statement object again, all of them would be closed.

  12. #12
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Stephen Douglas View Post
    Hmm... Can you give the link to
    Don't even begin to tell me that you don't know where the [url=http://java.sun.com/javase/6/docs/api/[/url] docs are. See the opening paragraph to Statement.

    You need to read these opening paragraphs. They, usually, exist for a reason and, many times, contain very important information.

Similar Threads

  1. Replies: 3
    Last Post: 12-20-2009, 04:22 PM
  2. Replies: 4
    Last Post: 08-11-2009, 12:31 PM
  3. Help about Guess the Numbers Program in java
    By macfrik in forum New To Java
    Replies: 6
    Last Post: 03-25-2009, 04:59 AM
  4. guess number game
    By mistah in forum New To Java
    Replies: 10
    Last Post: 11-23-2008, 04:37 AM
  5. sample of guess high and low game
    By pouria62 in forum AWT / Swing
    Replies: 1
    Last Post: 10-26-2008, 01:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •