Updating user profile

Updating user profile

how should i provide user to update his profile with edit option including entered data by user should be shown in jsp page fileds

View Answers

October 3, 2012 at 12:25 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>

October 3, 2012 at 12:25 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);
}
%>

Ads









Related Tutorials/Questions & Answers:
Updating user profile
Updating user profile  how should i provide user to update his profile with edit option including entered data by user should be shown in jsp page.... When the user clicks the particular edit button, that data will get shown
coding for updating profile
coding for updating profile  coding for updating profile
Advertisements
ModuleNotFoundError: No module named 'user_profile'
ModuleNotFoundError: No module named 'user_profile'  Hi, My Python... 'user_profile' How to remove the ModuleNotFoundError: No module named 'user_profile' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'user_profile'
ModuleNotFoundError: No module named 'user_profile'  Hi, My Python... 'user_profile' How to remove the ModuleNotFoundError: No module named 'user_profile' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-spirit-user-profile'
ModuleNotFoundError: No module named 'django-spirit-user-profile'  Hi...: No module named 'django-spirit-user-profile' How to remove the ModuleNotFoundError: No module named 'django-spirit-user-profile' error? Thanks
ModuleNotFoundError: No module named 'django-user-profile'
ModuleNotFoundError: No module named 'django-user-profile'  Hi, My... named 'django-user-profile' How to remove the ModuleNotFoundError: No module named 'django-user-profile' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-user-profile'
ModuleNotFoundError: No module named 'django-user-profile'  Hi, My... named 'django-user-profile' How to remove the ModuleNotFoundError: No module named 'django-user-profile' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo12-addon-base-user-role-profile'
ModuleNotFoundError: No module named 'odoo12-addon-base-user-role-profile' ...: ModuleNotFoundError: No module named 'odoo12-addon-base-user-role-profile' How to remove... to install padas library. You can install odoo12-addon-base-user-role-profile
ModuleNotFoundError: No module named 'odoo12-addon-base-user-role-profile-example'
ModuleNotFoundError: No module named 'odoo12-addon-base-user-role-profile...: ModuleNotFoundError: No module named 'odoo12-addon-base-user-role-profile-example...-user-role-profile-example' error? Thanks   Hi, In your
updating & deleting an employee
updating & deleting an employee  can anyone help out me please? advance thanks warm regards
Updating using AngularJS
Updating using AngularJS  Shopping.html <!DOCTYPE HTML PUBLIC... one more button for updating items in the table for Updating Items in Shopping.html. On clicking updating button for each row ( as like Remove button in each
profile display
profile display  Is it possible to create a user profile in Servlet and JSP   Please visit the following links: http://www.roseindia.net/servlets/web-application.shtml http://www.roseindia.net/jsp/user-registration
profile display
profile display  How to create a user profile in JSP   Please visit the following links: http://www.roseindia.net/servlets/web-application.shtml http://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
profile display
profile display  Create Jobseeker's profile in JSP and Servlet   Please visit the following links: http://www.roseindia.net/servlets/web-application.shtml http://www.roseindia.net/jsp/user-registration-form-using
Updating multiple value depending on checkboxes
Updating multiple value depending on checkboxes  Hi .. I want to Update the multiple values of database using checkboxes and want to set the session for selected checkboxes..? please answer if any one knows as soon as possible
Updating from MySQL 5.0 to 5.5 cPanel
Updating from MySQL 5.0 to 5.5 cPanel   Updating from MySQL 5.0 to 5.5 cPanel
profile display
profile display  how to display matching jobs in jobseeker's profile using jsp-servlets?   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user
profile page
profile page  sir, i am beginer in php i am creating simple web site.i am creating login form.the user login he can any status,photo update.he can display in home pages in all user login.but problem in user goto profile page
profile display
profile display  Search page to display matching results in JSP and Servlet   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user-search.shtml
Update Profile
Update Profile       Update Profile This facility is used for updating user... user wishes to change their information, he may proceed by clicking on Update
profile display
profile display  how to display matching Results using jsp-servlet?   Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user-search.shtml http
profile display
profile display  Fetch Matching jobs in JSP Servlet  Please visit the following links: http://www.roseindia.net/servlets/search.shtml http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/jsp
how to code-updating some details n some details r unchanged
how to code-updating some details n some details r unchanged  i have... : bloodgroup : my requirement is to update the details of user. and i had written the update query,but with that query all the details are updating... my doubt
update profile
update profile  coding for update profile
updating an access database with visual basic 2010
updating an access database with visual basic 2010  I am building a program in visual basic 2010 that connects to an access database. I was wondering if you could help me figure out the code for the save button. When
Ios Swift developer for updating current app
Ios Swift developer for updating current app  Hi, I have previously developed iOS application in Swift programming language. This application is developed in Swift and some of the Objective C libraries. Developer must know
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am having a multithreaded process which replicates the data from many table to one... inserting/updating to database. I dont know what is the issue but it was never
Starting MySQL.The server quit without updating PID file
Starting MySQL.The server quit without updating PID file  Starting MySQL.The server quit without updating PID file (/var/lib/mysql/xxxxxx.pid
what is wrong with my JSP codes for updating a form?
what is wrong with my JSP codes for updating a form?  Hi experts, I have tried to emulate a code from a textbook but it doesn't work in my program. Hope someone can advise me where I had gone wrong. Tks. I've set up my
Editing the Profile
Editing the Profile  how to populate drop-down menu instead of text box in editing the profile
Starting MySQL....The server quit without updating PID file
Starting MySQL....The server quit without updating PID file  Hi, My... error: Starting MySQL....The server quit without updating PID file (/var/lib/mysql/xxxxx.pid). MySQL Restart fails and the server quit without updating PID

Ads