Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以每 5 秒在我的 java servlet 中执行一次查询?因为我需要数据库中的数据值每隔几秒钟更新我网站中的条形图。
ResultSet rset = stmt.executeQuery(sqlStr);
while(true){ Thread.sleep(5000); ResultSet rset = stmt.executeQuery(sqlStr); }
你可以试试这个。此外,我不确定您的完整要求是什么。
您应该有一个用于轮询的 javascript 函数。假设该函数被调用poll。然后,您可以这样做:
poll
var polling = function(interval) { poll(); setTimeout(polling, interval); };