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 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 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
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 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
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
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
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
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"
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
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
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
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
ZF Data Update in DB
Edit Record in Zend Framework: Now if someone wants to change, update or edit...;view->title = "Edit Book"; $this->view->headTitle..._TO_REPLACE_14 Now make necessary changes and click the save button, it will update
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  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
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
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... UpdateClobExample shows how to update data of CLOB type in mysql database through
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
JDBC Video tutorial - How to update Data in a MySQL Database?
in Java for updating the data in a MySQL database table. We have used the update statement to update the data into the table. JDBC allows the programmers to run... - Following is the sql query which is used to update the data. String sql = "
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
update query
update query  using oops concept in php.. How to update the data from databse ? with program example
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
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...; select * from contact   </select> <!--- Update 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
i want to update values
i want to update values  in my form i have 2 submit buttons one for edit and another for update on page load all my details need to fetch from... pressing edit button the update button should be disabled please help me to write
Video Tutorial: How to update data in the MySQ?
How to update data in the MySQ? It is necessary to keep a real-time data and that calls to update data in the database. We modify values from rows and columns using the Update statement. Here we shall explain on how to update data
JDBC Batch Update Example
; } Batch Update Example You can update data in a table batch. To update...(updateQuery1); and finally commit the connection. An example of batch update...:Alligarh 7:Pawan:BBA:Darbhanga 8:Ram:BCA:Patna 9:Data Structures:Program
update profile
update profile  coding for update profile
how to update
how to update   conditional update
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
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
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 image
update image  sir, I want to do update image into database
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
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:ADS_TO_REPLACE_1 Hibernate Tutorials Thanks   Hi Friend,ADS_TO_REPLACE_2 Please visit
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
Update SQL Query Example
;In this video I will teach you how to use the update query to update the data...Update SQL Query Example  Hi, I am beginner in SQL (MySQL) and trying to learn Update SQL Query with Example code. Can anyone explain me the SQL

Ads