我的数据库中有yyyy-mm-dd hh:mm:ss格式的Date_time字段。我在我的数据库中存储了8天的数据。现在我想要每15分钟一次的数据。它的解决方案是什么?请帮帮我......
我的数据库中有yyyy-mm-dd hh:mm:ss格式的Date_time字段。我在我的数据库中存储了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 n jquery一无所知。
答案 0 :(得分:1)
使用此功能,我认为它可以帮助您
setInterval(function() {
// place your code here
}, 15 * 60 * 1000); // for 15 mins
答案 1 :(得分: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