nataraju
data grid with edit and delete options at each row.
6 Answer(s)      4 years and 9 months ago
Posted in : JSP-Servlet

i want to display the table data in the format of data grid with edit and delete options at each row. i need it very urgently. advance thanks .

Advertisement
View Answers

May 10, 2011 at 5:15 PM


We are proving you an application.

1)application.jsp:

<%@ page import="java.sql.*" %>
<html>
<head>
<script language="javascript">
function editRecord(id){
    var f=document.form;
    f.method="post";
    f.action='edit.jsp?id='+id;
    f.submit();
}
function deleteRecord(id){
    var f=document.form;
    f.method="post";
    f.action='delete.jsp?id='+id;
    f.submit();
}
</script>
</head>
<body>

<br><br>
<form method="post" name="form">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";

int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><input type="button" name="edit" value="Edit" style="background-color:green;font-weight:bold;color:white;" onclick="editRecord(<%=rs.getString(1)%>);" ></td>
<td><input type="button" name="delete" value="Delete" style="background-color:red;font-weight:bold;color:white;" onclick="deleteRecord(<%=rs.getString(1)%>);" ></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

2)edit.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<form method="post" action="update.jsp">
<table border="1">
<tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr>
<%
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "select * from employee where id='"+no+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
%>
<tr>
<td><input type="text" name="name" value="<%=rs.getString("name")%>"></td>
<td><input type="text" name="address" value="<%=rs.getString("address")%>"></td>
<td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td>
<td><input type="text" name="email" value="<%=rs.getString("email")%>"></td>
<td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
</tr>
<%
}
}
catch(Exception e){}
%>
</table>
</form>


May 10, 2011 at 5:16 PM


3)update.jsp:

<%@page import="java.sql.*"%>
<%
String ide=request.getParameter("id");
int num=Integer.parseInt(ide);
String name=request.getParameter("name");
String address=request.getParameter("address");
int contact=Integer.parseInt(request.getParameter("contact"));
String email=request.getParameter("email");
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();
st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'");
response.sendRedirect("/examples/jsp/application.jsp");
}
catch(Exception e){
System.out.println(e);
}
%>

4)delete.jsp:

<%@ page import="java.sql.*" %> 
<%
int id = Integer.parseInt(request.getParameter("id"));
try{
           Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("delete from employee where id="+id+"");
           response.sendRedirect("application.jsp");
}
catch (Exception e){
System.out.println(e);
}
%>


May 10, 2011 at 5:47 PM


Thank you very much for your answer.



May 16, 2011 at 12:35 PM


Hi. The code you sent was very useful to me. But if I want to send two values from one page to another page how can i send two values. In

f.action

how can i write another variable.

Please respond quickly if you know the answer.



February 21, 2012 at 11:41 PM


what is the database provided in this. table name and their fields.

please reply quickly, i need is urgently



August 23, 2012 at 11:20 AM


Application is working fine ...

but the movement i click on edit button its not displaying any values .. wat might be the prob .. ?

reply soon










Related Tutorials/Questions & Answers:
data grid with edit and delete options at each row.
data grid with edit and delete options at each row.  i want to display the table data in the format of data grid with edit and delete options at each row. i need it very urgently. advance thanks
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
Advertisements
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts  Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...="500"></td><td><input type="button" value="Delete" name
delete and edit options in struts
delete and edit options in struts   Hi, I am doing an web application... errors but the edit and delete operations were not working, so please modify my...;/action> <!-- end of Edit items --> <!-- Delete Items
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
Grid rows delete issue
Grid rows delete issue  I have a grid having rows with Remove button... event of dropdown also,so if we delete middle row and then remove all rows on onchange of dropdown then because of rows indexing issue,they can't get middle row
delete row
delete row  how to delete row using checkbox and button in php... if(isset($_POST['delete'])) { for($i=0;$i<$row;$i++) { $delete... into the html table. Along each table row there is a checkbox consists of id
add row in grid using dojo
add row in grid using dojo  add row in grid using dojo
edit data
edit data  sir i want to do edit a particular customers information after he logs in, i am also using sessions. thank you
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
Delete and add row from Table View iPhone
Delete and add row from Table View iPhone In this tutorial will learn how to delete and also how to add row into the table view iPhone, with the help of edit... of items (or rows) that may be divided into sections. Each row may display strings
sqlite database delete row
sqlite database delete row  How to delete row from SQLite Database?    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM aListDB WHERE id='%@'",details.ids
importing data and edit that data
importing data and edit that data   hello sir i have data in excel sheet which contain 2 rows and i want to import that data to ms access and edit that data like adding new columns and new rows and creating new tables
data grid - JSP-Servlet
data grid  how can we implement data grid (we have data grid... to implement data grid in jsp Thanks varun kumar  Hi friend, I... information. http://www.roseindia.net/jsp/data-grid.shtml Thanks
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery(hql); int row = query.executeUpdate(); if (row == 0
uitableview manually delete row
uitableview manually delete row  uitableview manually delete row   NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; [array removeObjectAtIndex:indexPath.row]; if(![array count]) [indexes addIndex
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
delete multiple row using checkbox
delete multiple row using checkbox  how to delete multiple row in a table which is connected to database using checkbox
delete multiple row using checkbox
delete multiple row using checkbox  how to delete multiple row in a table which is connected to database using checkbox
insert , edit , and delete button in one jsp page
insert , edit , and delete button in one jsp page  hello I want to ask about the way of creating a jsp page contains insert , edit , and delete buttons and manipulate data in database directly. any help please or hints
Adding button to each row for the table and adding row to another table
Adding button to each row for the table and adding row to another table  Hi I need to add button to each line in the table(Table data is retrived form database) and need to add that column data which we click in the specified
Update / Edit data
from database and display in the html table. At each row, there is a button which...Update / Edit data  Hello, i want to create a page to edit or update user data in the data base. the thing is, when i click on submit reference
data grid - JSP-Servlet
data grid  i am trying to do the example in the following link http://www.roseindia.net/jsp/data-grid.shtml but i am not able to find... this example  Hi friend, To visit again http://www.roseindia.net/jsp/data