Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jquery jsp to update table for every 15 secs. Db with more than 20000 records  RSS feed

 
Ramprakash Palanivel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 -->
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
20000 records is a very small number in this context. The DB will have no problem handling that.

Unless you meant that you need to update 20K records in your web page, in which case you need to redesign the UI - no user wants (or can) to look at that much data, much less if it's changing all the time.

And Java code has no place in a JSP - you should properly implement MVC.
 
Ramprakash Palanivel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I am just asking instead of returning table sending json will be better?? Or is there any other ways will be better to optimize performance. I will be using pagination so displaying part I am not considering now. Just wanna know will this make my app crash or makes dead slow??? If so what will be the better way??
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to use paging, then you should only fetch the number of items that you will be displaying. Why fetch 20000 items if you are only going to show 20?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!