edit database using jsp and servlet

Ads
 

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

Ads









Related Tutorials/Questions & Answers:
edit database using jsp and servlet
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
edit values of database using jsp
edit 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 jsp
edit 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
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database... to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts... example using struts.if anyone knows how to do it..please help me.. thanks a lot
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
How to browse excel file and stored the contents into the database using jsp/servlet?
How to browse excel file and stored the contents into the database using jsp/servlet?  Hi.. I want to browse excel file and stored the file data into the My-sql database using jsp/servlet
How to display image in jsp from database using Servlet?
How to display image in jsp from database using Servlet?  Hi, How to display image in jsp from database using Servlet? Thanks   Hi, You will find code and example program at Retrieve image from database using Servlet
Image upload in mysql database using jsp servlet
Image 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
How to retrieve image from database using jsp and servlet?
How to retrieve image from database using jsp and servlet?  Hi, I am trying to find code for displaying the image from database in a JSP page. How to retrieve image from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet  please i need code to populate dropdown menu from mysql database using jsp and servlet. thanks
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
Retrieve database from the table dynamically in jsp from oracle using servlet
using java servlet from the database in the jsp page...Retrieve database from the table dynamically in jsp from oracle using servlet  Sir, I have created a table in oracle using eclipse, and added few
Retrieve image from database using servlet and display in JSP
Retrieve image from database using servlet and display in JSP  Hi, I... to use MySQL Database from JSP page. How to retrieve image from database using servlet and display in JSP? Thanks
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... by using servlet or jsp program by typing the output as like this below... the problem   Get data from database using servlet Retrieve data from
fetch and insert multiple rows into mysql database using jsp servlet
fetch and insert multiple rows into mysql database using jsp servlet  ... jsp form and want inserting it into my mysql database table. but i am having a problem to insert multiple rows into database using a single insert query
save multiple records into database using jsp/servlet mvc
save multiple records into database using jsp/servlet mvc  hai, this is my jsp where i have enter multiple username and password and save it to database in single hit user.jsp <form action="UserServlet" method="post
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my code.. In jsp ... <form name=frm method="post" action="Device">...;/tr> In servlet... try { String strpath
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my code.. In jsp ... <form name=frm method="post" action="Device">...; In servlet... try { String strpath=request.getParameter("Image
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
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?
servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ?   first registration with email , username, password after >> <> without
How to get the data from the database (Oracle) in console or in ie using servlet or jsp as Front end
How to get the data from the database (Oracle) in console or in ie using servlet or jsp as Front end  hello i have a simple problem in jsp in the sense to get data from the database like oracle . I have created one jsp
jsp and servlet
the data and delete the data,using jsp and servlet...jsp and servlet  I want to create a login form,which have many fields,and have a connectivity with thwe oracle database,and login form will have
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
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

Ads