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 that is a link to an edit page. The edit page needs to display all the house information from the database in the textboxes. Please help me to display the information in the textboxes.
Below is edit.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Property</title>
</head>
<body>
<h1><img src="images/logo.gif" width="100" height="100" /> LIT Realty <img src="images/logo.gif" width="100" height="100" /></h1>
<br>
<form id="editProperty" name="editProperty" method="get" action="EditPropertyServlet">
<p><em>Please edit any properties details</em></p>
Enter Street: <input type="text" name="street" />
<br><br>
Enter city: <input type="text" name="city" />
<br><br>
Enter Listing Number: <input type="text" name="listingNum" />
<br><br>
Enter Style Id: <input type="text" name="styleId" />
<br><br>
Enter Type Id: <input type="text" name="typeId" />
<br><br>
Enter number of bedrooms: <input type="text" name="bedrooms" />
<br><br>
Enter number of bathrooms: <input type="text" name="bathrooms" />
<br><br>
Enter square feet: <input type="text" name="squarefeet" />
<br><br>
Enter description: <input type="text" name="description" />
<br><br>
Enter lot size: <input type="text" name="lotsize" />
<br><br>
Enter garage size: <input type="text" name="garagesize" />
<br><br>
Enter garage Id <input type="text" name="garageId" />
<br><br>
Enter your agent id: <input type="text" name="agentId" />
<br><br>
Select photo: <input type="text" name="photo" />
<br><br>
Enter price: <input type="text" name="price" />
<br><br>
<input type="submit" value="Edit Property" name="editProperty" />
</form>
</body> </html>
and edit.servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
try
{
int id = Integer.parseInt(request.getParameter("id"));
String street = request.getParameter("street");
String city = request.getParameter("city");
int listingNum = Integer.parseInt(request.getParameter("listingNum"));
int styleId = Integer.parseInt(request.getParameter("styleId"));
int typeId = Integer.parseInt(request.getParameter("typeId"));
int bedrooms = Integer.parseInt(request.getParameter("bedrooms"));
int bathrooms = Integer.parseInt(request.getParameter("bathrooms"));
int squarefeet = Integer.parseInt(request.getParameter("squarefeet"));
String description = request.getParameter("description");
String lotsize = request.getParameter("lotsize");
int garagesize = Integer.parseInt(request.getParameter("garagesize"));
int garageId = Integer.parseInt(request.getParameter("garageId"));
int agentId = Integer.parseInt(request.getParameter("agentId"));
String photo = request.getParameter("photo");
double price = Double.parseDouble(request.getParameter("price"));
Connection conn = PropertyDB.doConnection();
PreparedStatement editpst = conn.prepareStatement("SELECT * from properties WHERE id =" + id); //need to get id from Show.jsp
editpst.setString(1,street);
editpst.setString(2,city);
editpst.setInt(3,listingNum);
editpst.setInt(4,styleId);
editpst.setInt(5,typeId);
editpst.setInt(6,bedrooms);
editpst.setInt(7,bathrooms);
editpst.setInt(8,squarefeet);
editpst.setString(9,description);
editpst.setString(10,lotsize);
editpst.setInt(11,garagesize);
editpst.setInt(12,garageId);
editpst.setInt(13,agentId);
editpst.setString(14,photo);
editpst.setDouble(15,price);
int i = editpst.executeUpdate();
if(i!=0)
{
pw.println("<br>Property has been updated");
}
else
{
pw.println("Failed to update the data");
}
}
catch (Exception e){
pw.println(e.getMessage());
}
}
}
View Answers
Related Tutorials/Questions & Answers:
edit database using jsp and servletedit 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
edit values of database using jspedit 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
Advertisements
edit values of database using jspedit 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
How to edit values in textboxes from database using jspHow 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
Upadate Database using updatable fields - JSP-ServletUpadate
Database using updatable fields Hi,
Thanks for previous answers.They were of Great Help !!!
I want to create a
jsp in which data is pulled from
database and displayed
in the updatable fields.Means after user
Image upload in mysql database using jsp servletImage upload in mysql
database using jsp servlet Hello, I need code to insert image in mysql
database, I have seen the code which is already in your portal but it is not inserting image into
database it save in the folder
fetch record from oracle database using jsp-servlet?fetch record from oracle
database using jsp-
servlet? how can i fetch data from oracle
database by
using jsp-
servlet. i'm
using eclipse, tomcat server and oracle
database and creating
jsp pages and also
using servlet Updating Ms Access Database using jsp - JSP-ServletUpdating Ms Access
Database using jsp Hi
I am new to
jsp and I am trying to update a record in an access
database. I only want to update part of the record because the other columns already have data. When I use Update
JSP Servlet Search and Edit - JSP-ServletJSP Servlet Search and Edit Hi,
I want to thank the people who... to the following
jsp. Also, when I use it for a character column, if the backend table...){
alert(id);
window.location.replace('http://localhost:8080/examples/
jsp Acees data from database using combo box - JSP-ServletAcees data from
database using combo box please let me how i access the data from
database when i select combo box combo2 having values Arts... value 11 or 12, otherwise combo box combo2 remain hide.
Here is
JSP's files
database - JSP-Servletdatabase how to downloaad a file(doc) from
database and store in any local system by
using servlet Block edit menu option - JSP-ServletBlock
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
Delete and edit data in xml file using JSPDelete 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 page authentication panel using jsp/servlet?jsp page authentication panel
using jsp/
servlet? I have 10
jsp jsp forms and 7 users and i want to grant variour permission like
edit,delete
and save for users dynamically on forms.So please refer me code
Backup MySQL Database - JSP-ServletBackup MySQL Database
Database Sir I have been reading Rose's india tutorial "
Using MySQL
Database with
JSP/
Servlet". In the Tutorial you have shown an example of backing up the
database. When I tried to backup
database upload to database - JSP-Servlet to upload a pdf file into
database(sqlserver2000)
using jsp. In roseindia some examples... into
database whenever
i want that uploaded pdf file i have to retrieve it from
database please help me friends thanks in advance it is very urgent
connection with database - JSP-Servlet and the connection with the
database using jsp code, I get exceptions that I have... with java code.
Is there any other way to establish a connection with
database in
jsp... with the
database by writing the program in java.
Following is the code:
import