Solved

TimerTask with a while loop

Posted on 2003-12-01
5
522 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
Comment Utility
Make sure you catch any exceptions that could occur
0
 
LVL 3

Accepted Solution

by:
monkesdb earned 20 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Good to hear its solved :-)

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now