如何以15分钟的时间间隔从系统时间的数据库获取数据?

问题描述:

我在我的数据库中有yyyy-mm-dd hh:mm:ss格式的Date_time字段。我在我的数据库中存储了8天的数据。现在我需要每15分钟的数据。它的解决方案是什么?请帮我...如何以15分钟的时间间隔从系统时间的数据库获取数据?

我有YYYY-MM-DD HH DATE_TIME领域:在我的数据库ss格式:毫米。我在我的数据库中存储了8天的数据。现在我需要每15分钟的数据。它的解决方案是什么?请帮我...

my code is: 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 

<%@ page import="java.sql.*" %> 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Fetching data from the database</title> 

</head> 
<body> 
    <table border="2"> 
     <tr> 
      <th>Inv_id</th> 
      <th>Inv_phase1_V</th> 
      <th>Inv_phase1_A</th> 
      <th>Inv_phase1_kW</th> 
     </tr> 
      <% 
      try 
      { 
       Class.forName("com.mysql.jdbc.Driver"); 
       String url="jdbc:mysql://localhost:3306/solar"; 
       String username="root"; 
       String password="root"; 
       Connection conn=DriverManager.getConnection(url,username,password); 
       String query="select Inv_id,Inv_phase1_V,Inv_phase1_A,Inv_phase1_kW from inverter_detail"; 
       Statement stmt=conn.createStatement(); 
       ResultSet rs=stmt.executeQuery(query); 

       while(rs.next()) 
       { 
        String Inverter_id = rs.getString("Inv_id"); 
        Double voltage = rs.getDouble("Inv_phase1_V"); 
        Double ampere = rs.getDouble("Inv_phase1_A"); 
        Double kiloWatt = rs.getDouble("Inv_phase1_kW"); 
       %> 
        <tr> 
         <td class="cotainer"><%=Inverter_id%></td> 
         <td><%=voltage%></td> 
         <td><%=ampere%></td> 
         <td><%=kiloWatt%></td> 
        </tr> 
       <% 
       } 
       %> 
       <% 
        rs.close(); 
        stmt.close(); 
        conn.close(); 
       } 
       catch(Exception e) 
       { 
        e.printStackTrace(); 
       } 
       %> 
     </table> 
    </body> 
</html> 

现在我想要每隔15分钟的时间间隔这个值。我能做什么???我没有更多关于JavaScript的jQuery的想法。

+0

请出示你迄今为止做了什么 - 在代码中。 – 2014-11-23 11:55:20

+0

你到目前为止尝试过什么?请阅读[我如何问一个好问题?](http://*.com/help/how-to-ask)。 – DavidPostill 2014-11-23 11:55:31

+0

请发布一些您现有的代码。一个类似的问题在这里回答http://*.com/questions/5052543/how-to-fire-ajax-request-periodically – Aditya 2014-11-23 11:57:04

使用此功能,我认为它可以帮助你

setInterval(function() { 

    // place your code here 

}, 15 * 60 * 1000); // for 15 mins 
+0

哎呀抱歉.....然后设置为15 * 1000 * 60 – user3566029 2014-11-23 12:14:25

您想使用Javascript功能来获取这些数据?如果你的答案是肯定的,你可以尝试使用window.setInterval(code, delay);。该函数重复执行代码片段,每次调用该函数时都会有固定的时间延迟。

例如:

var time = 2000, // Number of milliseconds 
 
    message = "Requesting data...<br>", // Message (Dont worty about this.) 
 
    container = $(".container"); 
 

 

 
setInterval(function() { 
 

 
    container.append(message); 
 

 
}, 2000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="container"> 
 
</div>

只需设定时间15分钟(900000毫秒)和你的方法将使从服务器的请求。这是一个可以帮助你的简单方法。

祝你好运!

WindowTimers.setInterval() - https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers.setInterval