Solved

TimerTask with a while loop

Posted on 2003-12-01
5
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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