Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

In this page you can find the example usage for org.hibernate Session update.

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:ServletActualizarTrabajador.java

protected void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    SessionFactory factory = HibernateUtilidades.getSessionFactory();
    Session sesion = factory.openSession();
    Transaction tranza = sesion.beginTransaction();

    String id = request.getParameter("id");
    String nombre = request.getParameter("nombre");
    String paterno = request.getParameter("paterno");
    String materno = request.getParameter("materno");

    Trabajador t = new Trabajador();
    t.setIdTrabajador(new Integer(id));
    t.setNombre(nombre);//from www. j ava2s  . c  om
    t.setPaterno(paterno);
    t.setMaterno(materno);
    sesion.update(t);
    tranza.commit();
    sesion.close();

    out.println("Trabajador Actualizado");
}

From source file:agent_update.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w w w.ja  va  2 s . c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, FileUploadException {
    response.setContentType("text/html;charset=UTF-8");

    HttpSession hs = request.getSession();
    PrintWriter out = response.getWriter();

    try {

        if (hs.getAttribute("user") != null) {
            Login ln = (Login) hs.getAttribute("user");
            System.out.println(ln.getUId());

            String fn = "";
            String lastn = "";
            String un = "";
            String state = "";
            String city = "";
            String area = "";
            String e = "";
            String ad1 = "";
            String ad2 = "";
            String num = "";
            String p = "";
            String des = "";
            String cmp = "";
            String work = "";
            String agentphoto = "";
            String agentname = "";
            int id = 0;

            // creates FileItem instances which keep their content in a temporary file on disk
            FileItemFactory factory = new DiskFileItemFactory();
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);

            //get the list of all fields from request
            List<FileItem> fields = upload.parseRequest(request);
            // iterates the object of list
            Iterator<FileItem> it = fields.iterator();
            //getting objects one by one
            while (it.hasNext()) {
                //assigning coming object if list to object of FileItem
                FileItem fileItem = it.next();
                //check whether field is form field or not
                boolean isFormField = fileItem.isFormField();

                if (isFormField) {
                    //get the filed name 
                    String fieldName = fileItem.getFieldName();

                    if (fieldName.equals("fname")) {
                        fn = fileItem.getString();
                    } else if (fieldName.equals("id")) {
                        id = Integer.parseInt(fileItem.getString());
                    } else if (fieldName.equals("lname")) {
                        lastn = fileItem.getString();
                    } else if (fieldName.equals("uname")) {
                        un = fileItem.getString();
                    } else if (fieldName.equals("state")) {
                        state = fileItem.getString();
                    } else if (fieldName.equals("city")) {
                        city = fileItem.getString();
                    } else if (fieldName.equals("area")) {
                        area = fileItem.getString();
                    } else if (fieldName.equals("email")) {
                        e = fileItem.getString();
                    } else if (fieldName.equals("address1")) {
                        ad1 = fileItem.getString();
                    } else if (fieldName.equals("address2")) {
                        ad2 = fileItem.getString();
                    } else if (fieldName.equals("number")) {
                        num = fileItem.getString();

                    } else if (fieldName.equals("pwd")) {
                        p = fileItem.getString();
                    }

                    else if (fieldName.equals("descrip")) {
                        des = fileItem.getString();
                    } else if (fieldName.equals("compname")) {
                        cmp = fileItem.getString();
                    } else if (fieldName.equals("workx")) {
                        work = fileItem.getString();
                    }

                } else {

                    agentphoto = new File(fileItem.getName()).getName();

                    System.out.println(agentphoto);
                    try {

                        // FOR UBUNTU add GETRESOURCE  and GETPATH

                        String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/profilepic/";
                        //                    String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"//";
                        System.out.println("====" + fp);
                        fileItem.write(new File(fp + agentphoto));
                    } catch (Exception ex) {
                        out.println(ex.toString());
                    }

                }

            }
            SessionFactory sf = NewHibernateUtil.getSessionFactory();
            Session ss = sf.openSession();
            Transaction tr = ss.beginTransaction();
            //            
            //           String state="";
            //            Criteria cr = ss.createCriteria(StateMaster.class);
            //            cr.add(Restrictions.eq("sId", Integer.parseInt(stateid)));
            //            ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list();
            //            System.out.println("----------"+ar.size());
            //            if(ar.isEmpty()){
            //                
            //            }else{
            //                state = ar.get(0).getSName();
            //                System.out.println("-------"+ar.get(0));
            //            }
            //            
            //            String city="";
            //            Criteria cr2 = ss.createCriteria(CityMaster.class);
            //            cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid)));
            //            ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>)cr2.list();
            //            System.out.println("----------"+ar2.size());
            //            if(ar2.isEmpty()){
            //                
            //            }else{
            //                city = ar2.get(0).getCityName();
            //                System.out.println("-------"+city);
            //            }
            //            
            //            String area="";
            //            Criteria cr3 = ss.createCriteria(AreaMaster.class);
            //            cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid)));
            //            ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>)cr3.list();
            //            System.out.println("----------"+ar3.size());
            //            if(ar3.isEmpty()){
            //                
            //            }else{
            //                area = ar3.get(0).getAreaName();
            //                System.out.println("-------"+area);
            //            }
            //            

            //       Criteria crr=ss.createCriteria(AgentDetail.class);
            //       crr.add(Restrictions.eq("uId", ln.getUId()));
            //       ArrayList<AgentDetail> arr=(ArrayList<AgentDetail>)crr.list();
            //       if(arr.isEmpty())
            //       {
            //           out.print("array empty");
            //       }
            //       else
            //       {
            //           AgentDetail agd=arr.get(0);
            AgentDetail agd2 = (AgentDetail) ss.get(AgentDetail.class, id);
            AgentDetail agd = new AgentDetail();

            agd.setUId(agd2.getUId());
            agd.setAId(agd2.getAId());
            agd.setACompanyname(cmp);
            agd.setADescription(des);
            agd.setAEmail(e);
            agd.setAFname(fn);
            agd.setAImg(agentphoto);
            agd.setALname(lastn);
            agd.setANo(num);
            agd.setAWorkx(work);
            agd.setACity(city);
            agd.setAArea(area);
            agd.setAState(state);
            agd.setAAddress1(ad1);
            agd.setAAddress2(ad2);
            agd.setAStatus(null);
            agd.setARating(null);
            agd.setAStatus("Accepted");
            // agd.getUId().setPwd(p);
            // agd.getUId().setUName(un);

            ss.evict(agd2);
            ss.update(agd);
            tr.commit();
            //       }

            RequestDispatcher rd = request.getRequestDispatcher("agentprofile.jsp");
            rd.forward(request, response);

        }
    }

    catch (HibernateException e) {
        out.println(e.getMessage());
    }
}

From source file:changepassword.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w  w w . j  a v a 2  s  . c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();
    String original_password = null;
    try {

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.getCurrentSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();

        String old_password = request.getParameter("current");
        String new_password = request.getParameter("new");

        if (hs.getAttribute("patient") != null) {

            Patient p1 = (Patient) hs.getAttribute("patient");
            Login l1 = (Login) ss.get(Login.class, p1.getUsedId().getUserId());
            original_password = l1.getPassword();
            // out.println(original_password);

            if (original_password.equals(old_password)) {

                l1.setPassword(new_password);
                ss.update(l1);

                p1.setUsedId(l1);
                hs.setAttribute("patient", p1);
                //  hs.setAttribute("patient", l1);
                tr.commit();
                request.setAttribute("msg", "Your password is updated.!");
                RequestDispatcher rd = request.getRequestDispatcher("changepassword_patient.jsp");
                rd.forward(request, response);

            } else {
                request.setAttribute("msg1", "enter your current password correctly");
                RequestDispatcher rd = request.getRequestDispatcher("changepassword_patient.jsp");
                rd.forward(request, response);

            }
        } else {
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    } catch (HibernateException he) {
        out.println(he.getMessage());
    } finally {

        out.close();
    }
}

From source file:admin_add_lab.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w  w.j a va2 s . c om*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();
        if (hs.getAttribute("admin") != null) {
            Admin a = (Admin) hs.getAttribute("admin");

            if (request.getParameter("status") != null && request.getParameter("lId") != null) {

                int apid = Integer.parseInt(request.getParameter("lId"));
                Lab lab1 = (Lab) ss.get(Lab.class, apid);
                if (request.getParameter("status").equals("approve")) {

                    lab1.setStatus("ACTIVE");

                    ss.update(lab1);

                    String subject = "Your Appointment is Approved.!";
                    String content = "Hi," + lab1.getLabName() + " " + "\n"
                            + "Your Request has been approved by Admin" + ".\n";
                    String mail = lab1.getWebsite();

                    String[] recipients = new String[] { mail };
                    //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"};  

                    if (new MailUtil().sendMail(recipients, subject, content)) {

                    }
                    request.setAttribute("msg", "Appointment accepted..!");

                } else if (request.getParameter("status").equals("reject")) {
                    lab1.setStatus("REJECTED");
                    ss.update(lab1);
                    String subject = "Your Request is Rejected.!";
                    String content = "Hi, " + lab1.getLabName() + " "
                            + "Your Request to join Cardiac Countermeasure has been rejected by admin"
                            + ".\n  ";
                    String mail = lab1.getWebsite();

                    String[] recipients = new String[] { mail };
                    //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"};  

                    if (new MailUtil().sendMail(recipients, subject, content)) {

                    }
                    request.setAttribute("msg", "Appointment rejected..!");
                }

            }

            Criteria cr = ss.createCriteria(Lab.class);
            //cr.add(Restrictions.eq("dId", a));
            cr.add(Restrictions.eq("status", "not Active"));
            ArrayList<Lab> da = (ArrayList<Lab>) cr.list();
            if (da.size() > 0) {
                request.setAttribute("da", da);
            }

            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("admin_add_lab.jsp");
            rd.forward(request, response);
        } else {
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }
    } catch (HibernateException he) {

        out.println(he.getMessage());
    } finally {
        out.close();
    }
}

From source file:changepassword_lab.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w w  w  . j  a v  a  2s  .c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String original_password = null;
    try {

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.getCurrentSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();

        String old_password = request.getParameter("current");
        String new_password = request.getParameter("new");

        if (hs.getAttribute("lab") != null) {

            Lab p1 = (Lab) hs.getAttribute("lab");
            Login l1 = (Login) ss.get(Login.class, p1.getUserId().getUserId());
            original_password = l1.getPassword();
            // out.println(original_password);

            if (original_password.equals(old_password)) {

                l1.setPassword(new_password);
                ss.update(l1);

                p1.setUserId(l1);
                hs.setAttribute("lab", p1);
                //  hs.setAttribute("patient", l1);
                tr.commit();
                request.setAttribute("msg", "Your password is updated.!");
                RequestDispatcher rd = request.getRequestDispatcher("change_password_lab.jsp");
                rd.forward(request, response);

            } else {
                request.setAttribute("msg1", "enter your current password correctly");
                RequestDispatcher rd = request.getRequestDispatcher("change_password_lab.jsp");
                rd.forward(request, response);

            }
        } else {
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    } catch (HibernateException he) {
        out.println(he.getMessage());
    } finally {

        out.close();
    }
}

From source file:analysis_criteria.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w w  w . j a v a 2  s  .c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {

        SessionFactory sf = NewHibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();

        String prstate = request.getParameter("state");
        String prcity = request.getParameter("city");
        String prarea = request.getParameter("area");
        String ptype = request.getParameter("type");
        String pbhk = request.getParameter("bhk");
        String przip = "";

        System.out.println("bhk is" + pbhk);
        System.out.println("type is" + ptype);

        String state = "";
        Criteria cr = ss.createCriteria(StateMaster.class);
        cr.add(Restrictions.eq("sId", Integer.parseInt(prstate)));
        ArrayList<StateMaster> ar = (ArrayList<StateMaster>) cr.list();
        if (ar.isEmpty()) {

        } else {
            StateMaster sm = ar.get(0);
            state = sm.getSName();

        }

        String city = "";
        Criteria cr2 = ss.createCriteria(CityMaster.class);
        cr2.add(Restrictions.eq("cityId", Integer.parseInt(prcity)));
        ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>) cr2.list();
        System.out.println("----------" + ar2.size());
        if (ar2.isEmpty()) {

        } else {
            city = ar2.get(0).getCityName();
            System.out.println("-------" + city);
        }

        String area = "";
        Criteria cr3 = ss.createCriteria(AreaMaster.class);
        cr3.add(Restrictions.eq("areaId", Integer.parseInt(prarea)));
        ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>) cr3.list();
        System.out.println("----------" + ar3.size());
        if (ar3.isEmpty()) {

        } else {
            area = ar3.get(0).getAreaName();
            System.out.println("-------" + area);
        }

        Criteria cr4 = ss.createCriteria(AreaMaster.class);
        cr4.add(Restrictions.eq("areaId", Integer.parseInt(prarea)));
        ArrayList<AreaMaster> ar4 = (ArrayList<AreaMaster>) cr4.list();
        System.out.println("----------" + ar4.size());
        if (ar4.isEmpty()) {

        } else {
            przip = ar4.get(0).getZip();
            System.out.println("-------" + przip);
        }

        out.print("after object 0");

        //            
        //            String s="select * from the_asset_consultancy.Filter_criteria;";
        //            
        //            SQLQuery query=ss.createSQLQuery(s);
        //            List<Filtercriteria> l=query.list();
        //          
        Criteria cr5 = ss.createCriteria(Filtercriteria.class);

        ArrayList<Filtercriteria> l = (ArrayList<Filtercriteria>) cr5.list();

        Filtercriteria old = l.get(0);
        System.out.println("this is old cr id:" + old.getCrId());

        Filtercriteria f = new Filtercriteria();

        f.setCrId(old.getCrId());

        f.setArea(area);

        out.print("after object 1");

        f.setBhk(pbhk);
        f.setType(ptype);
        f.setZip(przip);

        ss.evict(old);
        ss.update(f);

        out.print("after object 2");
        tr.commit();
        out.print("after object 3");

        out.print("after object 4");

        //for trial 
        HadoopProcessingClass.Do_Process();
        RequestDispatcher rd = request.getRequestDispatcher("show_growthrate");
        rd.forward(request, response);

        //Original code
        //            RequestDispatcher rd = request.getRequestDispatcher("analysis_search.jsp");
        //            rd.forward(request, response);

    } catch (HibernateException he) {
        out.print(he.getMessage());
    }
}

From source file:lab_profile.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  www.j av a  2s.  c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();

    try {

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss1 = sf.getCurrentSession();
        Transaction tr1 = ss1.beginTransaction();
        // tr1.begin();
        HttpSession hs = request.getSession();
        if (hs.getAttribute("lab") != null) {

            Lab li = (Lab) hs.getAttribute("lab");
            if (request.getParameter("btn_update") != null) {

                Addressdetails ad = li.getAddressid();
                String line = request.getParameter("line1");
                ad.setLine1(line.trim());
                ad.setLine2(request.getParameter("line2").trim());
                ad.setPincode(request.getParameter("pincode").trim());
                ss1.update(ad);

                li.setLabName(request.getParameter("p_firstname").trim());
                li.setWebsite(request.getParameter("p_lastname").trim());
                li.setContactNum(request.getParameter("gender").trim());

                // pi.setContactnum(request.getParameter("contact_num").trim());
                // pi.setEmailId(request.getParameter("email_id").trim());

                ss1.update(li);
                tr1.commit();
                hs.setAttribute("lab", li);
                request.setAttribute("pdata", li);
                RequestDispatcher rd = request.getRequestDispatcher("Lab_My_profile.jsp");
                rd.forward(request, response);
            }

            else {

                request.setAttribute("pdata", li);
                RequestDispatcher rd = request.getRequestDispatcher("Lab_My_profile.jsp");
                rd.forward(request, response);
            }
        } else {

            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    }

    catch (HibernateException he) {
        he.getMessage();
    }

    finally {
        out.close();
    }
}

From source file:property_update.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from ww  w  . ja va 2s  . com
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, FileUploadException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    HttpSession hs = request.getSession();
    try {
        if (hs.getAttribute("user") != null) {
            Login ln = (Login) hs.getAttribute("user");
            System.out.println(ln.getUId());

            String pradd1 = "";
            String pradd2 = "";
            String prage = "";

            String prbhk = "";
            String prdescrip = "";
            String prprice = "";

            String state = "";
            String city = "";
            String area = "";
            String prname = "";
            String prtype = "";
            String prphoto = "";
            String prphoto1 = "";
            String prphoto2 = "";
            String prphoto3 = "";
            String prfarea = "";
            int prid = 0;

            FileItemFactory factory = new DiskFileItemFactory();
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload(factory);

            //get the list of all fields from request
            List<FileItem> fields = upload.parseRequest(request);
            // iterates the object of list
            Iterator<FileItem> it = fields.iterator();
            //getting objects one by one
            while (it.hasNext()) {
                //assigning coming object if list to object of FileItem
                FileItem fileItem = it.next();
                //check whether field is form field or not
                boolean isFormField = fileItem.isFormField();

                if (isFormField) {
                    //get the filed name 
                    String fieldName = fileItem.getFieldName();

                    if (fieldName.equals("pname")) {
                        //getting value of field
                        prname = fileItem.getString();
                        System.out.println(prname);
                    } else if (fieldName.equals("price")) {
                        //getting value of field
                        prprice = fileItem.getString();
                        System.out.println(prprice);
                    } else if (fieldName.equals("pid")) {
                        prid = Integer.parseInt(fileItem.getString());

                    } else if (fieldName.equals("state")) {
                        state = fileItem.getString();
                    } else if (fieldName.equals("city")) {
                        city = fileItem.getString();
                    } else if (fieldName.equals("area")) {
                        area = fileItem.getString();
                    } else if (fieldName.equals("pbhk")) {
                        prbhk = fileItem.getString();
                        System.out.println(prbhk);
                    } else if (fieldName.equals("pdescription")) {
                        prdescrip = fileItem.getString();
                        System.out.println(prdescrip);

                    } else if (fieldName.equals("ptype")) {
                        prtype = fileItem.getString();
                        System.out.println(prtype);

                    } else if (fieldName.equals("paddress1")) {
                        pradd1 = fileItem.getString();
                        System.out.println(pradd1);
                    } else if (fieldName.equals("paddress2")) {
                        pradd2 = fileItem.getString();
                        System.out.println(pradd2);
                    } else if (fieldName.equals("page")) {
                        prage = fileItem.getString();
                        System.out.println(prage);
                    } else if (fieldName.equals("pfarea")) {
                        prfarea = fileItem.getString();
                        System.out.println(prfarea);
                    } else if (fieldName.equals("prid")) {
                        prid = Integer.parseInt(fileItem.getString());
                        System.out.println("prid is " + prid);
                    }

                } else {

                    String fieldName = fileItem.getFieldName();

                    if (fieldName.equals("pic1")) {
                        //getting name of file
                        prphoto = new File(fileItem.getName()).getName();
                        //get the extension of file by diving name into substring
                        //  String extension=custphoto.substring(custphoto.indexOf(".")+1,custphoto.length());;
                        //rename file...concate name and extension
                        // custphoto=ln.getUId()+"."+extension;
                        try {
                            // FOR UBUNTU add GETRESOURCE  and GETPATH

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }
                    }

                    if (fieldName.equals("pic2")) {

                        prphoto1 = new File(fileItem.getName()).getName();

                        try {

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto1));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }
                    }

                    if (fieldName.equals("pic3")) {

                        prphoto2 = new File(fileItem.getName()).getName();

                        try {

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto2));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }

                    }

                    if (fieldName.equals("pic4")) {
                        prphoto3 = new File(fileItem.getName()).getName();

                        try {

                            String fp = "/home/rushin/NetBeansProjects/The_Asset_Consultancy/web/images/property/";
                            // String filePath=  this.getServletContext().getResource("/images/profilepic").getPath()+"\\";
                            System.out.println("====" + fp);
                            fileItem.write(new File(fp + prphoto3));
                        } catch (Exception ex) {
                            out.println(ex.toString());
                        }
                    }
                }
            }

            SessionFactory sf = NewHibernateUtil.getSessionFactory();
            Session ss = sf.openSession();
            Transaction tr = ss.beginTransaction();

            //           String state="";
            //            Criteria cr = ss.createCriteria(StateMaster.class);
            //            cr.add(Restrictions.eq("sId", Integer.parseInt(stateid)));
            //            ArrayList<StateMaster> ar = (ArrayList<StateMaster>)cr.list();
            //            System.out.println("----------"+ar.size());
            //            if(ar.isEmpty()){
            //                
            //            }else{
            //                state = ar.get(0).getSName();
            //                System.out.println("-------"+ar.get(0));
            //            }
            //            
            //            String city="";
            //            Criteria cr2 = ss.createCriteria(CityMaster.class);
            //            cr2.add(Restrictions.eq("cityId", Integer.parseInt(cityid)));
            //            ArrayList<CityMaster> ar2 = (ArrayList<CityMaster>)cr2.list();
            //            System.out.println("----------"+ar2.size());
            //            if(ar2.isEmpty()){
            //                
            //            }else{
            //                city = ar2.get(0).getCityName();
            //                System.out.println("-------"+city);
            //            }
            //            
            //            String area="";
            //            Criteria cr3 = ss.createCriteria(AreaMaster.class);
            //            cr3.add(Restrictions.eq("areaId", Integer.parseInt(areaid)));
            //            ArrayList<AreaMaster> ar3 = (ArrayList<AreaMaster>)cr3.list();
            //            System.out.println("----------"+ar3.size());
            //            if(ar3.isEmpty()){
            //                
            //            }else{
            //                area = ar3.get(0).getAreaName();
            //                System.out.println("-------"+area);
            //            }
            //            
            //       Criteria crr=ss.createCriteria(AgentDetail.class);
            //       crr.add(Restrictions.eq("uId", ln.getUId()));
            //       ArrayList<AgentDetail> arr=(ArrayList<AgentDetail>)crr.list();
            //       if(arr.isEmpty())
            //       {
            //           out.print("array empty");
            //       }
            //       else
            //       {
            //           AgentDetail agd=arr.get(0);
            PropDetail prd = (PropDetail) ss.get(PropDetail.class, prid);
            System.out.println("old object id is " + prd.getPId());
            PropDetail prd1 = new PropDetail();

            prd1.setUId(prd.getUId());
            prd1.setPId(prd.getPId());
            prd1.setPDescription(prdescrip);
            prd1.setPImg1(prphoto1);
            prd1.setPImg2(prphoto2);
            prd1.setPImg3(prphoto3);
            prd1.setPImg4(prphoto);
            prd1.setPAdd1(pradd1);
            prd1.setPAdd2(pradd2);
            prd1.setPAge(Integer.parseInt(prage));
            prd1.setPBhk(prbhk);
            prd1.setPFloor(Integer.parseInt(prfarea));
            prd1.setPGmap(null);
            prd1.setPName(prname);
            prd1.setPPrice(Integer.parseInt(prprice));
            prd1.setPStatus(null);
            prd1.setPCity(city);
            prd1.setPArea(area);
            prd1.setPState(state);
            prd1.setPType(prtype);

            ss.evict(prd);
            ss.update(prd1);
            tr.commit();

            RequestDispatcher rd = request.getRequestDispatcher("getstate?id=9");
            rd.forward(request, response);
        }

    } catch (HibernateException e) {
        out.println(e.getMessage());
    }
}

From source file:changepassword_doc.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w w w.  j ava  2  s. c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    String original_password = null;
    try {

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.getCurrentSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();

        String old_password = request.getParameter("current");
        String new_password = request.getParameter("new");

        if (hs.getAttribute("doctor") != null) {

            Doctor p1 = (Doctor) hs.getAttribute("doctor");
            Login l1 = (Login) ss.get(Login.class, p1.getUserId().getUserId());
            original_password = l1.getPassword();
            // out.println(original_password);

            if (original_password.equals(old_password)) {

                l1.setPassword(new_password);
                ss.update(l1);

                p1.setUserId(l1);
                hs.setAttribute("doctor", p1);
                //  hs.setAttribute("patient", l1);
                tr.commit();
                request.setAttribute("msg", "Your password is updated.!");
                RequestDispatcher rd = request.getRequestDispatcher("change_password_doc.jsp");
                rd.forward(request, response);

            } else {
                request.setAttribute("msg1", "enter your current password correctly");
                RequestDispatcher rd = request.getRequestDispatcher("change_password_doc.jsp");
                rd.forward(request, response);

            }
        } else {
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    } catch (HibernateException he) {
        out.println(he.getMessage());
    } finally {

        out.close();
    }
}

From source file:lab_view_appointment.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w  ww  .  j  a  va  2 s  .  c o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    PrintWriter out = response.getWriter();

    try {

        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        Transaction tr = ss.beginTransaction();
        HttpSession hs = request.getSession();

        if (hs.getAttribute("lab") != null)

        {
            Lab a = (Lab) hs.getAttribute("lab");

            if (request.getParameter("status") != null && request.getParameter("appoid") != null)

            {

                int apid = Integer.parseInt(request.getParameter("appoid"));
                LabAppointment lab1 = (LabAppointment) ss.get(LabAppointment.class, apid);
                if (request.getParameter("status").equals("approve")) {

                    lab1.setStatus("APPROVED");
                    lab1.setDate(request.getParameter("apdate"));
                    lab1.setTime(request.getParameter("aptime"));
                    ss.update(lab1);

                    String subject = "Your Appointment is Approved.!";
                    PatienttestDetail pp = new PatienttestDetail();
                    String content = "Hi, " + lab1.getPId().getPFirstname() + "\n"
                            + "Your appointment has been approved by " + lab1.getLId().getLabName() + ".\n"
                            + "Date : " + lab1.getDate() + "\n" + "Time : " + lab1.getTime() + "\n";

                    String mail = lab1.getPId().getEmailId();

                    String[] recipients = new String[] { mail };

                    if (new MailUtil().sendMail(recipients, subject, content)) {

                    }
                    request.setAttribute("msg", "Appointment accepted..!");
                }

                else if (request.getParameter("status").equals("reject")) {
                    lab1.setStatus("REJECTED");
                    ss.update(lab1);
                    String subject = "Your Appointment is Rejected.!";
                    String content = "Hi, " + lab1.getPId().getPFirstname() + " "
                            + "Your appointment has been rejected by " + lab1.getLId().getLabName()
                            + ".\n anil ";
                    String mail = lab1.getPId().getEmailId();

                    String[] recipients = new String[] { mail };
                    //String[] bccRecipients = new String[]{"sunilkotadiya777@gmail.com"};  

                    if (new MailUtil().sendMail(recipients, subject, content)) {

                    }
                    request.setAttribute("msg", "Appointment rejected..!");

                }

            }

            Criteria cr = ss.createCriteria(LabAppointment.class);
            cr.add(Restrictions.eq("lId", a));
            cr.add(Restrictions.eq("status", "Pending"));
            ArrayList<LabAppointment> da = (ArrayList<LabAppointment>) cr.list();
            if (da.size() > 0) {
                request.setAttribute("da", da);
            }

            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("Lab_Appointment_List.jsp");
            rd.forward(request, response);
        } else {
            tr.commit();
            RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
            rd.forward(request, response);
        }

    }

    catch (HibernateException he) {

        he.getMessage();
    }

    finally {
        out.close();
    }

}