Solved

TimerTask with a while loop

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse shortcuts 9 62
egit plugin on eclipse 8 82
Oracle SQL syntax check  without executing 6 74
What browser will run Java? 7 49
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

808 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