jsp :how to edit table of data displayed using jsp when clicked on edit button

jsp :how to edit table of data displayed using jsp when clicked on edit button

i have a jsp program which displays data in the form of table ..now i want to edit this information in table when clicked on edit button and save the data when clicked on save button.. how can i do this

View Answers

May 15, 2012 at 2:13 PM

The given code retrieve data from database and display in the html table. At each row, there is a button which consists of that particular id. When the user clicks the particular edit button, that data will get shown in another page and allow the user to update the record.

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();
}
</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>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>

May 15, 2012 at 2:14 PM

continue..

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>

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);
}
%>

May 15, 2012 at 6:49 PM

My database is xml..How can i do the same thing when database is xml..


August 23, 2012 at 11:21 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:
jsp :how to edit table of data displayed using jsp when clicked on edit button
jsp :how to edit table of data displayed using jsp when clicked on edit button  i have a jsp program which displays data in the form of table ..now i... the data when clicked on save button.. how can i do
jsp :how to edit table of data displayed using jsp when clicked on edit button
jsp :how to edit table of data displayed using jsp when clicked on edit... want to edit this information in table when clicked on edit button and save the data when clicked on save button.. how can i do this   The given
Advertisements
extract data fom table when a button is clicked in front end page using mysql5.0 and tomcat6.0
extract data fom table when a button is clicked in front end page using mysql5.0 and tomcat6.0   sir, i want to extract data from table which is stored in mysql5.0 databse, when a button is clicked in front end page using
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
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
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
edit database using jsp and servlet
edit database using jsp and servlet  I am creating a website using jsp and servlets that is used to view houses from a database. I want to be able to edit the information of each house. showAll.jsp shows all the houses and beside
sorting and filtering the displayed table data using jsp and xml
sorting and filtering the displayed table data using jsp and xml  I have created a xml file and a jsp file, which uses DOM parser to display... that is displayed in web page. How to do it ??? Please help as soon as possible
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
uitableview edit done button
call, when Edit / done Button is clicked. In that case you need not to write...uitableview edit done button  How to add Edit / Done button in UITableView with an action on click?   UITableview Edit done Button To add
Update / Edit data
field that i have prepared under the submit button. btw, im using jsp. thank you... consists of that particular id. When the user clicks the particular edit button... user data in the data base. the thing is, when i click on submit reference
UINavigationBar Edit Button
UINavigationBar Edit Button  UINavigationBar Edit Button Given is the code that adds a edit button item as a nav bar item in your UINavigation Controller. -(void)viewDidLoad; { [super viewDidLoad]; UINavigationBar* navBar
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
get a value when a radio button clicked - JSP-Servlet
get a value when a radio button clicked  sorry sir my actual probs is that 1st i m callig a jsp in that i m displaying a table where i used a radio button to access a value(also used u r code),then in this jsp i m having a forms
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database... to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts... example using struts.if anyone knows how to do it..please help me.. thanks a lot
get a value when a radio button clicked - JSP-Servlet
get a value when a radio button clicked  Here is my code sir please help me if any changes in the code please give me sir thanks in advance...; //System.out.println("******* id in jsp login Is ******" +id); f.submit
How to edit values in textboxes from database using jsp
How to edit values in textboxes from database using jsp  Hi RoseIndia, I need help to solve my technical problem, i want to edit values in textboxes from database table using jsp, here is my code Please can anyone help me
Drop down and radio button value on edit action
Drop down and radio button value on edit action  HI, I have... the value from dropdown and radio button.. But the problem goes with edit action.. While the edit form is being displayed it gets all the values from the database
radio button value on edit action
radio button value on edit action  This is my edit.jsp code...In my......Problem 'm facing is on edit action 'm not retrieving radio button value..i have...="cancel" class="button" onclick="return f2(edit_customer)"> <
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
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
Login Box appears when a button on the webpage is clicked
Login Box appears when a button on the webpage is clicked  How to create a Login Box on a web page that appears only when a button that is already present on the page is clicked
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks... on certain buttons (say an img of a "+" sign). When the user does that, I would like JSP to do some internal check and then increment the value of a number
JSP - Update displayed content & session variables when user clicks on a button - JSP-Servlet
JSP - Update displayed content & session variables when user clicks... on certain buttons (say an img of a "+" sign). When the user does that, I would like JSP to do some internal check and then increment the value of a number
Edit the record.
Edit the record.  sir, I have a table consist of huge data.I have displayed that data.side of them there is an edit button which will edit that particular record.after editing the data i want to edit another row which is next
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
edit the flash video file using html5
edit the flash video file using html5  hi iam vivek i have a flash file i want to edit it with html5 please reply
Block edit menu option - JSP-Servlet
Block edit menu option  I am doing a jsp project. I have to control number of characters in a text area upto a limit. How can i block pasting through edit menu and pasting through short cut key [ctrl+v
Displaying image when clicked on URL in jsp - JSP-Servlet
Displaying image when clicked on URL in jsp  Hi, I am using... For Screenshot : abc.jpg here abc.jpg is a url and when clicked would show me an image... *.jpg images displayed depending upon the page url clicked. Please guide me
edit msword file - using java - Java Beginners
edit msword file - using java  I want to edit ms word file. That is input file font style is times new romen and font size is 12. I want the output file font style is bookman old style and size is 20. How to possible java
How to search the selected item in row table using radia button in JSP?
How to search the selected item in row table using radia button in JSP?  How to search the selected item in row table using radia button in JSP
how to remove spell check in flex when button is clicked
how to remove spell check in flex when button is clicked  how to remove spell check when button is clicked in rich text editor control
JSP Servlet Search and Edit - JSP-Servlet
to the following jsp. Also, when I use it for a character column, if the backend table...JSP Servlet Search and Edit  Hi, I want to thank the people who... Post). The code works fine when I've incorporated it in my web application, its
ModuleNotFoundError: No module named 'odoo8-addon-website-mail-snippet-table-edit'
: ModuleNotFoundError: No module named 'odoo8-addon-website-mail-snippet-table-edit...-website-mail-snippet-table-edit' error? Thanks   Hi, In your...-website-mail-snippet-table-edit python with following command: pip install
how to disable submit button in jsp using servlet when some condition is satisfied
how to disable submit button in jsp using servlet when some condition is satisfied  how to disable submit button in jsp using servlet when some condition is satisfied
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript  when click on the next.../paging.shtml http://www.roseindia.net/jsp/data-grid.shtml Pagination in JSP http
Need to edit PDF files using java - Java Beginners
Need to edit PDF files using java  Hi , I need to edit the pdf files say i need to insert and replace strings like that.. will any one help me to find this..the library must be a freeware sply if it is iText..or other than
Refresh Button returns null point exception when clicked
Refresh Button returns null point exception when clicked  Dear all Please assist with the following: How to rectify a piece of code for the refresh button in java. When clicking the button it returns an error "null point
create, edit ,open simple documents using java - Swing AWT
create, edit ,open simple documents using java   In my program I... in text area? Then how to transfer text in that document back to text area... want to use Java Swing or JSP? Do you want to create word document file
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
jsp query - JSP-Servlet
jsp query  in first division there is one table which contains data with edit button... when i will click on edit button that division will become hidden and new division come with all related data
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select...' in textbox and click on search button it should show me all the title names
Edit word document Headers and Footers using POI Library in java?
Edit word document Headers and Footers using POI Library in java?  Hi All, I need code to modify the Header and Footer contents of a ms-word template using POI or JACOB libraries. Could any one help me? Thanks Advance
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap.  I have a jsp page which ask for project ID,team name,member name according to this data i have to retrieve their details from the database(oracle). I have
ID using get the databse latest value and displayed in jsp
ID using get the databse latest value and displayed in jsp   I have... ... once click the submit button the data will be stored in mysql database... in the form (it means latest values) ... how to retrive that values using ID
ModuleNotFoundError: No module named 'edit'
ModuleNotFoundError: No module named 'edit'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'edit' How to remove the ModuleNotFoundError: No module named 'edit' error
ModuleNotFoundError: No module named 'edit'
ModuleNotFoundError: No module named 'edit'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'edit' How to remove the ModuleNotFoundError: No module named 'edit' error

Ads