Home Answers Viewqa JSP-Servlet Update / Edit data

 
 


Amirul Afiq
Update / Edit data
5 Answer(s)      a year ago
Posted in : JSP-Servlet

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 number, i want the data for that reference no to automatically appear in the form field that i have prepared under the submit button.

btw, im using jsp. thank you.

View Answers

May 14, 2012 at 3:56 PM


this is a snapshot of my page. so when i click on the display record, all the field will be filled with data from the database base on the reference number.


May 14, 2012 at 4:01 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 14, 2012 at 4:03 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);
}
%>

October 19, 2012 at 11:17 AM


edit.jsp rs.getString(1) rs.getString(2) rs.getString(3) rs.getString(4)


September 23, 2012 at 10:34 PM


Edit button is not redirecting to edit page...how to do it in the above code...please let me know









Related Pages:
Update / Edit data
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..., that data will get shown in another page and allow the user to update
data update
edit/update data and saved them into that table again... displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
data update
data update  sir, I have a table consist of huge data.I have displayed that data in table format be side of a table an edit button which will edit... the data and edit it based on subjectcode(varchar)this should be done using jsp
Edit the record.
that particular record.after editing the data i want to edit another row which is next... or some email.according to the sorted page we should fetch the data and edit...Edit the record.  sir, I have a table consist of huge data.I have
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
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 particular edit button, that data will get shown in another page and allow the user
JSP Servlet update patient data - JSP-Servlet
_update="Data has been successfully inserted!"; String title="Update Message...JSP Servlet update patient data  Hi Friend, I'm attaching my inserting patient data servlet as requested. I tried your posted code, its
ZF Data Update in DB
Edit Record in Zend Framework: Now if someone wants to change, update or edit... ..... public function editAction() { $this->view->title = "Edit..., it will update the book table
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 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
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
delete and edit options in struts
;!-- end of Update Stock items --> <!-- get items to Edit -->...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
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...; <br> <br> <br> <form name="update" method
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...; <br> <br> <br> <form name="update" method
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...;br> <br> <br> <form name="update" method="get
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...:bold;" align="center">Edit User</td></tr> <tr><
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
JPA update data Example
JPA update data Example       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. To update the data
update database
update database  hi.. i want to know how the valuesof database can be updated in the jsf-jpa framework when the drop down button is clicked the data will be displayed in the data table and if some changes has to be made
JPA update data
JPA update data       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. Create "
JPA update data
JPA update data       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. Create "JPAUpdate"
Update statement
Update statement  I create a access database my program When I click add button bata are adds to the my data base but when i click update button my database is not update I write this program using 3 differfnt notepad pages MY
Dojo Inline Edit Box
Dojo Inline Edit Box          In this section, you will learn how to edit any data. The InlineEditBox provides the better facility for editing any data and save it.  Try
JPA update data
JPA update data       In this section, you know how to update the database data through the jpa. You follow the following steps for updating the data. 1--Create
update data to mysql database through JTextField
update data to mysql database through JTextField  I am getting an error, when i am updating a data to mysql database through JTextField. Send me the code used to solve my error. public void update(){ try
radio button value on edit action
radio button value on edit action  This is my edit.jsp code...In my... provided show edit add and delete link for each customer that is searched...Problem 'm facing is on edit action 'm not retrieving radio button value..i have
how update JTable after adding a row into database
= podaci; edit_table = tedit; change_data = dchange; } public void...how update JTable after adding a row into database  J have two classes, listed below, one is table model, and second show data from database
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
Non-edit Combobox with auto fill - Swing AWT
Non-edit Combobox with auto fill  Hi, I have a non-edit... typed by the user. For example, ["Callisto", "Charls", "chim"] are the data... the characters typed by the user in Document(Model for Edit view of the JCombobox
Read Excel data using JSP and update MySQL databse
Read Excel data using JSP and update MySQL databse  HOw to read excel data using JSP and update MySQl database
Dynamic-update not working in Hibernate.
you are running your update, new data is added in your table in place of the existing data update .The main reason is you are not beginning transaction. So import...Dynamic-update not working in Hibernate.  Why is dynamic update
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... format and I need to update MySQL tables with new experimental data. How can I
How to save image after edit in php
How to save image after edit in php  Hello, I have create a simple image editor with the effected of brightness, contrast, and desaturat etc. I have...;body> <form name="form1" action="index.php" enctype="multipart/form-data
textfields and update - SQL
to the textfields using jdbc?and at the same time update the items on the database..   Hello Friend As per ur 1st Q: Read the data from... basis u want to update database? can u clarify? Thanks Rajaniakant 
The UPDATE Statement
The UPDATE Statement       The UPDATE statement is used to modify the data in the database table through a specified criteria. In the given syntax of update statement the keyword SET
JSP edit multiple rows
JSP edit multiple rows In this tutorial, you will learn how to update... and allow the user to edit that particular record. User can edit multiple rows from...[a]; String tit=title[a]; st.executeUpdate("update book set author='"
iBatis Update -Updating data of a table
iBatis Update -Updating data of a table   ... will introduce you how you can update data in data table with the iBatis. In iBatis...;!--- Update data of Contact table -->   <update id

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.