Solved

TimerTask with a while loop

Posted on 2003-12-01
5
527 Views
Last Modified: 2008-03-03
I want to query my database every minute to view the latest information. I am using a TimerTask with a while loop embedded in it. Everything seems to work fine, the task executes at the proper intervals, the DB connection is fine, but my while loop will only go through one iteration. It never goes to the next record in the recordset even though there are multiple records.
Does anybody know what I am doing wrong?

Here is a code snippet with the unimportant info taken out.

class RemindTask extends TimerTask {
      public void run() {
            try{
                  // Set up DB stuff
                                                .
                                               // End of DB setup

                  while(rs.next()){      
                        aucID=rs.getInt("aucID");      
                        System.out.println("ID is: "+aucID);
                  }
                  rs.close();
                  stmt.close();
                  con.close();      
            }
0
Comment
Question by:Arawn
5 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 20 total points
ID: 9853023
Make sure you catch any exceptions that could occur
0
 
LVL 3

Accepted Solution

by:
monkesdb earned 20 total points
ID: 9853110
there's only one record.

1) those two lines don't exit the while.

2) rs.next() returns true if the new current row is valid; false if there are no more rows.

there's no reason for it to exit until it has finished all the records.

check your SQL

please post the...
// Set up DB stuff
// End of DB setup
0
 
LVL 92

Assisted Solution

by:objects
objects earned 20 total points
ID: 9853156
print out your sql, and run it externally to confirm how many records are returned.
looks like only 1
0
 
LVL 4

Author Comment

by:Arawn
ID: 9858118
Thanks for the help guys. It turned out to be some really sloppy SQL on my part that would end up returning one record even though I knew there was more. I gave all of you points for your help.

Cheers,

Arawn
0
 
LVL 92

Expert Comment

by:objects
ID: 9861610
Good to hear its solved :-)

http://www.objects.com.au
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

713 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