1

Is it possible to execute a query in my java servlet every 5 seconds? As i need the data values inside my database to update my bar graph in my website every few seconds.

ResultSet rset = stmt.executeQuery(sqlStr);
Zainau
  • 95
  • 4
  • 13
  • 1
    Easier to refresh your web page every 5 seconds through Javascript. – Kayaman Mar 25 '15 at 12:00
  • **Timer and TimerTask** Refer to this [question](http://stackoverflow.com/questions/12908412/print-hello-world-every-x-seconds) – Sasha Mar 25 '15 at 12:16

2 Answers2

0
while(true){
            Thread.sleep(5000);
            ResultSet rset = stmt.executeQuery(sqlStr);
        }

You can Try this. Moreover, I am not sure what's your complete requirement here is.

Nitsshukla
  • 27
  • 1
  • 7
0

You should have a javascript function for polling. Let's suppose the function is called poll. Then, you can do it like this:

var polling = function(interval) {
    poll();
    setTimeout(polling, interval);
};
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175