• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 -->
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic