2014-11-23 106 views
0

我在我的數據庫中有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://stackoverflow.com/help/how-to-ask)。 – DavidPostill 2014-11-23 11:55:31

+0

請發佈一些您現有的代碼。一個類似的問題在這裏回答http://stackoverflow.com/questions/5052543/how-to-fire-ajax-request-periodically – Aditya 2014-11-23 11:57:04

回答

1

使用此功能,我認爲它可以幫助你

setInterval(function() { 

    // place your code here 

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

哎呀抱歉.....然後設置爲15 * 1000 * 60 – user3566029 2014-11-23 12:14:25

1

您想使用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

相關問題