Share on Google+Share on Google+

2 Answer(s)      5 years and 5 months ago
Posted in : HTML

how to retrieve data from mysql database in grid form using html and servlets? urgent....


View Answers

November 8, 2011 at 11:39 AM

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class PaginationInServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
PrintWriter out = response.getWriter();
Connection conn = null;
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
ResultSet rs1 = null;
ResultSet rs2 = null;
PreparedStatement ps1=null;
PreparedStatement ps2=null;

int showRows=5;
int totalRecords=5;
int totalRows=nullIntconvert(request.getParameter("totalRows"));
int totalPages=nullIntconvert(request.getParameter("totalPages"));
int iPageNo=nullIntconvert(request.getParameter("iPageNo"));
int cPageNo=nullIntconvert(request.getParameter("cPageNo"));

int startResult=0;
int endResult=0;
String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
String query2="SELECT FOUND_ROWS() as cnt";
if( {
out.println("<html><h3>Pagination of JSP page</h3><body><form>");
out.println("<input type='hidden' name='iPageNo' value='<%=iPageNo%>'>");
out.println("<input type='hidden' name='cPageNo' value='<%=cPageNo%>'>");
out.println("<input type='hidden' name='showRows' value='<%=showRows%>'>");
out.println("<table width='100%' cellpadding='0' cellspacing='0' border='1' >");
out.println("<tr><td>Roll No</td><td>Name</td><td>Marks</td><td>Grade</td></tr>");
if(totalRows<(iPageNo+showRows)) {
catch(Exception e){
out.println("<tr><td colspan='3'><div>");
int i=0;
int cPage=0;
if(totalRows!=0) {
int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
out.println("<a href=PaginationInServlet?iPageNo="+prePageNo+"&cPageNo="+prePageNo+"'> << Previous</a>");
out.println("<a href=PaginationInServlet?iPageNo="+i+"style=cursor:pointer;color: red><b>"+i+"</b></a>");
else if(i<=totalPages){
out.println("<a href=PaginationInServlet?iPageNo="+i+">"+i+"</a>");
if(totalPages>totalRecords && i<totalPages){
out.println("<a href=PaginationInServlet?iPageNo="+i+"&cPageNo="+i+"> >> Next</a>");
out.println("<b>Rows "+startResult+"-"+endResult+"Total Rows"+totalRows+"</b></div></td></tr></table></form></body></html>");

November 8, 2011 at 11:39 AM



catch(Exception e)
catch(Exception ex){}
public int nullIntconvert(String str){
int num=0;
if(str==null) {
else if((str.trim()).equals("null")) {
else if(str.equals("")) {
catch(Exception e) { }
return num;

For the above code, we have used following database table:

CREATE TABLE `student` (
`rollNo` bigint(40) NOT NULL auto_increment,
`name` varchar(40) default NULL,
`marks` varchar(40) default NULL,
`grade` varchar(40) default NULL,
PRIMARY KEY (`rollNo`)

Related Tutorials/Questions & Answers:
HTML GRID  how to retrieve data from mysql database in grid form using html and servlets? urgent....   import*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class
Ajax grid
Ajax grid  Hi, How I can create ajax grid in my program? Thanks
Jsp Grid
="ISO-8859-1"%> &lt;%@ page contentType="text/html"%> &lt;%@ page import...()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional... http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> &lt
Grid Layout Container in Flex4
Grid Layout Container in Flex4: The Grid Layout Container is a MX container. There is no Spark equivalent. It's like an HTML Table. You can arrange... in a row and each cell can have a Grid container. The default Horizontal and Vertical
Nitobi Grid is not working in IE10/IE11
Nitobi Grid is not working in IE10/IE11  Nitobi grid is working in IE8, but not working in IE10/IE11. we are using above two javascript files to open the grid
Sigma grid -- Ajax-enabled JavaScript grid
Sigma grid -- Ajax-enabled JavaScript grid       Sigma Grid Sigma Grid is a freely open source AJAX editable data grid, written in pure javascript for displaying and inline
Html  in the web page if judge select the age and category then automatically under that conditions the details will be display in the form of grid give me that code in html and java
HTML  I want the following fields as in the form of grid view Fields... of the work,image of the work,points from the judges and above of this grid form i... and age buttons then automatically displays the grid form and display the values
How to export grid into excel
How to export grid into excel  Hi, i created a grid panel i have to export it to the excel. please help me by some sample code. thanks in advance. cool day dude
GRID IN JSP  I m creating one ERP project in which i need to fill the data from the data base in a grid in jsp page. So pls any one provide the code
java + grid - Java3D
java + grid  i need to give the output of the application in the form of a grid in XY-plane,the grid should have different colors for regions of different value range
Grid Problem - Java Beginners
Grid Problem  Hi Deepak Plz take seriously I m telling u detail. Steps: 1:- there r one form,this form belong to grid. and two... belong to different table.but in main form,all data going in the grid(with join
data grid - JSP-Servlet
data grid  how can we implement data grid (we have data grid in in jsp. can u please send me the sample code and also the possible ways to implement data grid in jsp Thanks varun kumar  Hi friend, I
Java with Grid - Ajax
Java with Grid  please check this URL grid on above link is made in dotnet. i want to make [b]same UI[/b] as in Java. which
give me a grid example in php
give me a grid example in php  give me easy code example of grid in php like mysql editor
add row in grid using dojo
add row in grid using dojo  add row in grid using dojo
Grid rows delete issue
Grid rows delete issue  I have a grid having rows with Remove button to remove rows,But we also havae an facility to remove those rows on onchange event of dropdown also,so if we delete middle row and then remove all rows
Grid layout container
Grid layout container       Grid container places the child components in columns and rows. This is very similar to html tables. Inside the Grid tag, GridRow tag is used to represent
HTML  how can we design the gird form view in html i want the following fields in the grid form The fields are Name of the candidate,Title... me the coding for this in html
Nitobi Grid V3
Nitobi Grid V3       Display & edit tabular data in various web browsers(IE, Firefox & Netscape) with Ajax-powered Nitobi Grid V3. With minimal coding, Grid delivers responsive
editable grid in jsp
editable grid in jsp  i want to create editable grid in jsp for invoice so that i can insert multiple product at a same to create that in jsap, plz reply   We are providing you the code where we have specified
count asterisk in a grid - Java Beginners
count asterisk in a grid  I need to write a program that uses a recursive method to count the number of asterisk in a square grid
how to insert a summary values in grid
how to insert a summary values in grid  how to insert a summary value in grid
HTML  How can we increase the row size in the grid form view of the table.I want to store the maximum 4 details of the candidate in one page of the grid table view
Grid in Echo3
Grid in Echo3       Grid is a two-dimensional structure on which the designers and developers can organize their components in a well and easy to understand manner. Grid class
HTML  What is Semantic HTML? What are the reasons for validating a HTML
HTML  What is Semantic HTML? What are the reasons for validating a HTML
HTML  What is SPAN in HTML
grid view in java - Java Beginners
grid view in java  Is it possible to create dynamic grid view to display data from database. if yes. how ??   Hi Friend, Yes, you can. Try the following: import java.awt.*; import java.sql.*; import
html  How to add the calendar in html code
HTML  What is HTML? What is a Hypertext link
Java Spring Hibernate Struts Training How to display button as a link in vaadin? hi change navbar dropdown color in bootstrap How to remove the background color of bootstrap menu bar? How to change color of opened Bootstrap drop down toggle? Setting bootstrap container background color Help school all activities and admision process.. add one row after another date make a webpage HTMl HTMl Source code how to apply globalisation to a world wide application how to print HTML using javascript or Jquery How to recover from google panda update? How to survive google panda 4.0 update How to find if you have been hit by Panda 4.0 Design a web page using XHTML and JavaScript that does the followings: ffmpeg converting file mp4 to mov JavaScript How to Disable Catch-all Emails on CPanel z-index always on top What is Web hosting Database and HTML web development trainee Uploading files Image Gallery Image Gallery dropdown How to redirect from a HTML page? Easiest method for expiring the css and js headers HTML WITH AJAX VB 6 Read Web Page Header string palindrom using vbscript? html button How to add mod_deflate to apache without recompiling How to use place hoder in IE(version : 8) Html Software Question div align left css Fetching data from excel file on other website and display in interactive graph form where do I find the fix for tree view catalog not expanding and collapsing correctly for roseindia shopping cart 1.1 pass to next page to enter into a particular page only if the username,password and listbox value mtches hi Cricket stadium ticket booking design Need some help creating an order form. HTML div tag HTML div tag


Advertisement null