Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Update / Edit data

Have Programming Question? Ask it here!
 
 
 


Amirul Afiq
Update / Edit data
5 Answer(s)      a year and 11 months 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.


Advertisement
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 Tutorials/Questions & Answers:
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
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
Advertisements
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
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
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 :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
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"
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
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
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
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
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
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
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
update
update  Predict and justify the output of the following code snippet written by the developer to update the Status table: String str = "UPDATE m...://localhost:3306/roseindia", "root", "root"); String str = "UPDATE Status SET
Servlet Example To Update Mysql Clob Data
Servlet Example To Update Mysql Clob Data    This example shows how to update CLOB data in the database. In our... to update data of CLOB type in mysql database through the servlet program
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data... procedure for inserting data into oracle database as bind variable and same for update also thank you
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
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes ... and entered the values in the textbox then it should get update in the database.I have succesfully updated when I am clickinga single checkbox but I want to update
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
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
Edit image - XML
Edit image  How to edit my Image Document Online?  Just visit http://www.onlinedocumentconversion.com/ and register there, upload and convert your image
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
how to edit a record in hibernate?
how to edit a record in hibernate?  how to edit a record in hibernate?   Hi Friend, Please visit the following link: Hibernate Tutorials Thanks   Hi Friend, Please visit the following link: Hibernate
Edit cron entry
Edit cron entry   Hi, What is the command to Edit cron entry in linux? Regards Deepak Kumar   Hi, You can use the following command to open cron configuration in vi editor: crontab -e After editing just save
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
uitableview edit done button
uitableview edit done button  How to add Edit / Done button in UITableView with an action on click?   UITableview Edit done Button To add " Edit / Done button " in UITableView add the given code in UIView Controller
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
edit database using jsp and servlet
("Failed to update the data"); } } catch...edit database using jsp and servlet  I am creating a website using... to edit the information of each house. showAll.jsp shows all the houses and beside
Advertisements
 

 

 

DMCA.com