I have a need to refresh my database for every 15 seconds. I have to work with
jsp ajax and jquery. For small amount of db entries it is ok but My application is going to handle huge records more than 20000. In my present scenario, Im forwarding request to another jsp page which communicate db and returns a table as result. Instead of this what are things I need to do?? This is just a sample application only. On success I am gonna implement using Spring, hibernate. So instead of table returning json or arraylist like that will help??
Here is my code:
## index.jsp ##
<!-- begin snippet: js hide: false -->
<!-- language: lang-html -->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>DbRefresh Sample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var url="/DbRefresh/FetchRecords.jsp";
$(document).ready(function(){
$.ajaxSetup({cache:false});
setInterval(function(){
$("#table").load(url);
},15000)
});
</script>
</head>
<body>
<div id="table"></div>
</body>
</html>
<!-- end snippet -->
----------
## FetchRecords.jsp ##
<!-- begin snippet: js hide: false -->
<!-- language: lang-html -->
<%@page import="java.text.SimpleDateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.servlet.*" %>
<%@page import="javax.servlet.http.*" %>
<%@page import="java.util.*,java.sql.*,java.io.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee Portal</title>
</head>
<body>
<%!
Connection con;
Statement s;
ResultSet rs; %>
<%
String name=request.getParameter("st");
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","root");
s=con.createStatement();
rs=s.executeQuery("SELECT Name, Age FROM test");
}catch(Exception e){ e.printStackTrace(); }
%>
<div id="dt_table">
<table border='4' cellpadding='6' cellspacing='3' width="300px">
<thead>
<tr bgcolor="66FF00">
<th> Name</th>
<th> Age</th>
</tr></thead>
<% while(rs.next())
{ %>
<tr><td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td></tr>
<% } %>
</table></div>
</body>
</html>
<!-- end snippet -->