Results 1 to 12 of 12
- 04-10-2010, 06:17 PM #1
resultset.next() = false ;; Can't Guess why.. please help.
I don't even know what exactly to ask for... sO i have pasted the code itself..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); } }
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. thnxLast edited by Stephen Douglas; 04-11-2010 at 02:52 PM.
The Quieter you become the more you are able to hear !
- 04-10-2010, 06:20 PM #2
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 !
- 04-10-2010, 06:28 PM #3
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 !
- 04-10-2010, 09:46 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 04-11-2010, 02:53 PM #5
As the "blue" while loop in never entered so i guess it won't be effecting the execution of the "red" while loop.Uhm, you do know that the "red" while loop will never be entered when that "blue" while loop exists, right?
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 !!!!!!!!!!!!I don't know how you are testing the queryThe Quieter you become the more you are able to hear !
- 04-11-2010, 07:11 PM #6
can anybody?? answer my question. thnx in advance.
The Quieter you become the more you are able to hear !
- 04-11-2010, 07:14 PM #7
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 !
- 04-12-2010, 06:52 AM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 04-12-2010, 06:59 AM #9
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
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?I am actually testing this query on the "localhost/isqlplus".........Where?also the query is tested right in this code iteself....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.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 !!!!!!!!!!!!
- 04-12-2010, 10:13 AM #10
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 ..Is there any upper bound on the number of queries we can execute in one connection???.thnx :)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.The Quieter you become the more you are able to hear !
- 04-12-2010, 10:17 AM #11
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 04-12-2010, 10:21 AM #12
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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
-
how to convert string to int in guess number game in jsp
By tahir90 in forum New To JavaReplies: 3Last Post: 12-20-2009, 03:22 PM -
ResultSet next() returns false Yet Tuples Present
By mjz in forum JDBCReplies: 4Last Post: 08-11-2009, 11:31 AM -
Help about Guess the Numbers Program in java
By macfrik in forum New To JavaReplies: 6Last Post: 03-25-2009, 03:59 AM -
guess number game
By mistah in forum New To JavaReplies: 10Last Post: 11-23-2008, 03:37 AM -
sample of guess high and low game
By pouria62 in forum AWT / SwingReplies: 1Last Post: 10-26-2008, 12:57 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks