Re:Need Help for Editable Display table

Re:Need Help for Editable Display table

Hi Genius

i need a help in jsp to display editable display tag.

I able to show the datagrid in jsp but i cant edit in that.

My backend is with Mysql.

I need to fetch the data and edit it in the same grid..

Thanks in advance
Eswaramoorthy
View Answers

March 23, 2010 at 1:04 PM

Hi Friend,

Try the following code:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%!
public int nullIntconvert(String str){
int num=0;
if(str==null) {
str="0";
}
else if((str.trim()).equals("null")) {
str="0";
}
else if(str.equals("")) {
str="0";
}
try{
num=Integer.parseInt(str);
}
catch(Exception e) { }
return num;
}
%>
<%
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
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;
if(iPageNo==0){
iPageNo=0;
}
else{
iPageNo=Math.abs((iPageNo-1)*showRows);
}
String query1="SELECT SQL_CALC_FOUND_ROWS * FROM student limit "+iPageNo+","+showRows+"";
ps1=conn.prepareStatement(query1);
rs1=ps1.executeQuery();
String query2="SELECT FOUND_ROWS() as cnt";
ps2=conn.prepareStatement(query2);
rs2=ps2.executeQuery();
if(rs2.next()) {
totalRows=rs2.getInt("cnt");
System.out.println(totalRows);
}
%>
<html>
<h3>Pagination of JSP page</h3>
<body>
<form method="post" action="upgrid.jsp">
<input type="hidden" name="iPageNo" value="<%=iPageNo%>">
<input type="hidden" name="cPageNo" value="<%=cPageNo%>">
<input type="hidden" name="showRows" value="<%=showRows%>">
<table width="100%" cellpadding="0" cellspacing="0" border="1" >
<tr>
<td>Roll No</td>
<td>Name</td>
<td>Marks</td>
<td>Grade</td>
</tr>
<%
while(rs1.next()){
%>
<tr>
<td><input type="text" name="no" size="38" value="<%=rs1.getInt("rollNo")%>"></td>
<td><input type="text" name="name" size="38" value="<%=rs1.getString("name")%>"></td>
<td><input type="text" name="marks" size="38" value="<%=rs1.getInt("marks")%>"></td>
<td><input type="text" name="grade" size="38" value="<%=rs1.getString("grade")%>"></td>
</tr>
<%
}
%>
<%
try{
if(totalRows<(iPageNo+showRows)) {
endResult=totalRows;
}
else{
endResult=(iPageNo+showRows);
}
startResult=(iPageNo+1);
totalPages=((int)(Math.ceil((double)totalRows/showRows)));
}
catch(Exception e){
e.printStackTrace();
}
%>
<tr>
<td colspan="3">
<div>

March 23, 2010 at 1:06 PM

continue..

<%
int i=0;
int cPage=0;
if(totalRows!=0) {
cPage=((int)(Math.ceil((double)endResult/(totalRecords*showRows))));
int prePageNo=(cPage*totalRecords)-((totalRecords-1)+totalRecords);
if((cPage*totalRecords)-(totalRecords)>0){
%>
<a href="datagrid.jsp?iPageNo=<%=prePageNo%>&cPageNo=<%=prePageNo%>"> << Previous</a>
<%
}
for(i=((cPage*totalRecords)-(totalRecords-1));i<=(cPage*totalRecords);i++){
if(i==((iPageNo/showRows)+1)){%>
<a href="datagrid.jsp?iPageNo=<%=i%>" style="cursor:pointer;color: red"><b><%=i%></b></a>
<%
}
else if(i<=totalPages){
%>
<a href="datagrid.jsp?iPageNo=<%=i%>"><%=i%></a>
<%
}
}
if(totalPages>totalRecords && i<totalPages){
%>
<a href="datagrid.jsp?iPageNo=<%=i%>&cPageNo=<%=i%>"> >> Next</a>
<%
}
}
%>
<b>Rows <%=startResult%>-<%=endResult%>Total Rows<%=totalRows%> </b>
</div>
</td>
</tr>
</table>
<input type="submit" value="Update">
</form>
</body>
</html>
<%
try{
if(ps1!=null){
ps1.close();
}
if(rs1!=null){
rs1.close();
}

if(ps2!=null){
ps2.close();
}
if(rs2!=null){
rs2.close();
}
if(conn!=null){
conn.close();
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>

upgrid.jsp:

<%@ page import="java.sql.*" %>
<%
String d[] =request.getParameterValues("no");
if(d !=null) {
for(int i=0;i<d.length;i++) {
out.println(d[i]);
}
}
String name[] =request.getParameterValues("name");
if(name !=null) {
for(int i=0;i<name.length;i++) {
out.println(name[i]);
}
}
String marks[] =request.getParameterValues("marks");
if(marks !=null) {
for(int i=0;i<marks.length;i++) {
out.println(marks[i]);
}
}
String grade[] =request.getParameterValues("grade");
if(grade !=null) {
for(int i=0;i<grade.length;i++) {
out.println(grade[i]);
}
}
%>
<%
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");

Statement st=null;
st=conn.createStatement();
for(int a=0;a<30;a++){
String no=d[a];
String n=name[a];
String mar=marks[a];
String g=grade[a];
st.executeUpdate("update student set name='"+n+"', marks='"+mar+"', grade='"+g+"' where rollNo='"+no+"'");
}
}
catch(Exception e){
e.printStackTrace();
}
%>

For more information, visit the following link:

http://www.roseindia.net/jsp/data-grid.shtml

Thanks

March 23, 2010 at 1:07 PM

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`)
)

Thanks









Related Tutorials/Questions & Answers:
Re:Need Help for Editable Display table - JSP-Servlet
Re:Need Help for Editable Display table  Hi Genius
Re:Need Help for Editable Display table - JSP-Servlet
Re:Need Help for Editable Display table  Hi Genius i need a help in jsp to display editable display tag. I able to show the datagrid in jsp but i cant edit in that. My backend is with Mysql. I need to fetch the data
Advertisements
display uploaded file option in editable form
display uploaded file option in editable form  how to show the uploaded file in editable mode on the jsp in struts2.0
display uploaded file option in editable form
display uploaded file option in editable form  how to show the uploaded file in editable mode on the jsp in struts2.0
how can i display a editable result of form?
how can i display a editable result of form?  how can i display a editable result of form? i know how to display form result but the result is display on text. i cant modify them. i have a form with hundreds of checkbox. i want
i want to create invoice report editable. values should be taken from dabase and editable .. help out asap
i want to create invoice report editable. values should be taken from dabase and editable .. help out asap   i want to create invoice report editable. values should be taken from dabase and editable .. help out asap
i want to create invoice report editable. values should be taken from dabase and editable .. help out asap
i want to create invoice report editable. values should be taken from dabase and editable .. help out asap   i want to create invoice report .. help out asap
Display items in table
Display items in table  I have a listbox which has some items... in a table. I want these items to be displayed in the table to be unique...i.e. if I reselect those same items they should not be displayed in the table and may
display:table export only data
display:table export only data  I am using display:table tag with attribute export="true". Using that I can export table data in excel. Here one of the column is in hyper link. But i need to export only data not html tag . Can
how to use stringtokenizer on table? and display in table format.
display result in row format  how to use stringtokenizer on table? and display in table format
how to use stringtokenizer on table? and display in table format.
how to use stringtokenizer on table? and display in table format.  table is retrieved from mysql database and each row contains data like(java,c,c++,.net
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add... one help me out........... I tried this problem but iam only able to display
display of colors in a table - JSP-Servlet
display of colors in a table  Hi, If i have a table of 4 by 4 boxes, numbering from 1-16 in sequence, how do i make them display one column of one color and another column of another color? Thanks!  Hi Friend
display table details when selecting table name in drop down liat
display table details when selecting table name in drop down liat  ... be retrived from the database and display in the page... pls its urgent.. help me... database to the dropdownlist in jsp. Example: 1st i want to display the list
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add... one help me out........... I tried this problem but iam only able to display
Display table performing action on another table
Display table performing action on another table In this section, we have created two tables. The data in table 1 have shown as a result of the database. We have retrieved the values from the database and display
Editable Html
Editable Html  i have editable html table with following elements textbox(n),checkbox(n),sno,dropdownlist..this elements are generated in runtime... how to take the values from the table and insert into database.please gimme some
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 http://roseindia.net/jsp/servlet-jsp-data
how to display data in List Or grid or in table in Jsp
String P Value in List GIrd or Table please help am able to Print display data In out.print.ln on console But i need to display in List...how to display data in List Or grid or in table in Jsp   <%@page
Html form using JavaScript to display the table content
Html form using JavaScript to display the table content  HI There, Greetings, I am new to this java and I need your assistance. I have created... want to write a Html JavaScript coding to display the content from database
How to Display values from databse into table
How to Display values from databse into table  I want to display values from database into table based on condition in query, how to display that? For example i have some number of books in database but i want to display books
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program
editable datagrid
editable datagrid  How to create a editable datagrid in jsp,struts1.3,glassfish v2.x application server and database oracle using netbeans6.8 ide.... ThanksADS_TO_REPLACE_2   thanks but i want a editable grid,with the option
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display Records From MS Access Database To JTable. Plz Help Me  Hi Friend...){ System.out.println(e); } JTable table = new JTable(data, columnNames); TableColumn
how to display values from database into table using jsp
how to display values from database into table using jsp  I want to display values from database into table based on condition in query, how to display that? For example i have some number of books in database but i want
Dynamic retrieval od data from database and display it in the table at jsp
Dynamic retrieval od data from database and display it in the table at jsp  Hi friends.... Am creating software for chit fund.. I want to display the details of 20 members in a table format at jsp page by dynamically retrieving
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.  I am unable to show table data on JSP page using servlet and mysql. only two rows data i showing but in my database I have five fields
filter and display html table data using ajax - Ajax
filter and display html table data using ajax  Hi i am stuck up... to DisplayCategory.jsp i want to display the data retrieved from the session in a 2d array on DisplayCategory.jsp in the form of the html table using responseText. how to do
Display JSP selected listbox and checkbox in xml-please help me
Display JSP selected listbox and checkbox in xml-please help me  Hi... first page ,it will stored in XML file and at same time ,it should display second page containing second listlox , also in the second page ,it should display
how to display the selected row from the data table in model panel ??
how to display the selected row from the data table in model panel ??  the below displayed is my datatable:tableDatas.xhtml <rich...(); return dataList; } please help me out !~!!!!! i get the model panel but the values
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes... the secified table. rs = statement.executeQuery(QueryString); </code>
Problem With Combo Box Editable Property
Problem With Combo Box Editable Property  Hi I am new To Flex i had set Combo Box Editable Property as true. But I didn't get the property filtering... Started with "S" will Automatically Display as Combo Box Items. So will you
Editable JTree
Editable JTree Nodes        In this section, you will learn  to make JTree editable... then the following program will  help you a lot. Program Description:ADS
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.   I have the same problem.plz help me. I have MySQL DataBase/DB Name:lokesh; Table Name:TR_list; columns:nodename,packageno,TR
editable combobox method selection
editable combobox method selection  how to make an editable combobox that shows nothing initially but as a key is pressed it pops up and selects an item starting with that letter, subsequent keys would keep sorting from the list
how to use an editable combobox
how to use an editable combobox   Hello Everyone!!!!!!!! I have a jcombo box with certain values and i want to use it as an editable that means when user will type something in combobox, according to that text only matching item
Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well as in store that unchecked checkboxes in ARRAYLIST
Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well... need to delete all the table rows which contain CHECKED textboxes.and remaining... of it to work at various times, but I'm running out of time and I really need help
Display Blob(Image) from Mysql table using JSP
Display Blob(Image) from Mysql table using JSP In this section, we will display blob data(image) from Mysql database table using JSP code. A Blob stores a binary large object in the database table's row. Blob object contains
How to display all the rows in JSP ,MySQL select condition statement IN dept_table
is as follows.Plz help me to display all the rows that satisfy the condition...How to display all the rows in JSP ,MySQL select condition statement IN dept_table  I iam unable to display all the rows in JSP select statement from
How to display all the Select values from the MySQL database table in where condition= In JSP?
How to display all the Select values from the MySQL database table in where... to display all the select values from MySQL DB** only first value is displayed in the jsp file. @select * from table dept where dept_no=10;" jsp code i have used
editable grid in jsp
editable grid in jsp  i want to create editable grid in jsp...; <form name=myname method=post action="edit.jsp"> <table border="1">...;form name=myname method=post action="update.jsp"> <table border="1">
Non Editable Text File in java - Java Beginners
Non Editable Text File in java  Hello Sir ,I want to Show NonEditable TextFile on JButton Click which Contains User Manual of Project ,How I can Do It. plz Help Me
ModuleNotFoundError: No module named 'sphinxcontrib-editable'
ModuleNotFoundError: No module named 'sphinxcontrib-editable'  Hi...: No module named 'sphinxcontrib-editable' How to remove the ModuleNotFoundError: No module named 'sphinxcontrib-editable' error? Thanks   Hi
JComboBox Insert Edited Value Into Table
in to insert an editable value of JComboBox into a table. We will use an Java editor... of combo box will be inserted to the table and the combo box will made editable...JComboBox Insert Edited Value Into Table In this section we will read about
display
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
Help
Help   i have a html file.. i have take input and store in database .. Tell me the steps to perform.. i have xampp it includes mysql,tomacat,apache. and how display the data from datbase .. please explain
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
display the results ?? its urgent can u help me   displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
table
input from oracle table(my database table..) This is a very important table of my project.. Please help me out

Ads