Solved

TimerTask with a while loop

Posted on 2003-12-01
5
529 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

632 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