Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void UpdateUserDATA(User user) throws SQLException {
- PreparedStatement preparedStatement =null;
- try {
- Connection connection = getConnection();
- preparedStatement = connection.prepareStatement("update userregisteration set firstName=?, lastName=?, username=?,password=?, telephone=?, address=? where username=? ");
- preparedStatement.setString(1, user.getFirst_name());
- preparedStatement.setString(2, user.getLast_name());
- preparedStatement.setString(3, user.getUsername());
- preparedStatement.setString(4, user.getPassword());
- preparedStatement.setString(5, user.getContactNo());
- preparedStatement.setString(6, user.getAddress());
- preparedStatement.setString(7, user.getUsername());
- preparedStatement.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- if (preparedStatement != null) {
- preparedStatement.close();
- }
- }
- }
- package Controller;
- import DatabaseConnector.DatabaseConnectivity;
- import DatabaseConnector.UserDataConnector;
- import java.io.IOException;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import model.User;
- /**
- *
- * @author Thanuka_Senadheera
- */
- public class UserUpdateServlet extends HttpServlet {
- private final DatabaseConnectivity DBConnection = new DatabaseConnectivity();
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
- {
- resp.setContentType("text/html;charset=UTF-8");
- if (!DBConnection.ConnectionValid())
- {
- resp.sendRedirect("404/404.html"); //Connection to the database was not successful
- }
- else
- {
- HttpSession session = req.getSession();
- String username = (String) session.getAttribute("username");
- String password = (String) session.getAttribute("password");
- if (DBConnection.UserValidation(username, password))
- {
- UserDataConnector UDC = new UserDataConnector();
- User user = (User) session.getAttribute("user");
- try {
- UDC.UpdateUserDATA(user);
- } catch (SQLException ex) {
- Logger.getLogger(UserUpdateServlet.class.getName()).log(Level.SEVERE, null, ex);
- }
- session.setAttribute("user",user);
- req.setAttribute("message","Your details are successfully updated, Please Go to home page!");
- resp.sendRedirect("manageAccounts.jsp");
- }
- else
- {
- req.setAttribute("message","Account is invalid, Please SignUp!");
- req.getRequestDispatcher("Login.jsp").forward(req,resp);
- }
- }
- }
- }
- package model;
- import java.io.Serializable;
- /**
- *
- * @author Thanuka_Senadheera
- */
- public class User implements Serializable
- {
- private String first_name;
- private String last_name;
- private String username;
- private String password;
- private String contactNo;
- private String address;
- public User(String first_name,String last_name,String username,String password,String contactNo,String address)
- {
- this.first_name=first_name;
- this.last_name=last_name;
- this.username=username;
- this.password=password;
- this.contactNo=contactNo;
- this.address=address;
- }
- public User()
- {
- }
- public void setFirst_name(String first_name) {
- this.first_name = first_name;
- }
- public void setLast_name(String last_name) {
- this.last_name = last_name;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public void setContactNo(String contactNo) {
- this.contactNo = contactNo;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public String getFirst_name() {
- return first_name;
- }
- public String getLast_name() {
- return last_name;
- }
- public String getUsername() {
- return username;
- }
- public String getPassword() {
- return password;
- }
- public String getContactNo() {
- return contactNo;
- }
- public String getAddress() {
- return address;
- }
- /*
- @Override
- public String toString() {
- return "User [first_name=" + first_name + ", last_name=" + last_name
- + ", username=" + username + ", password=" + password + ", contactNo="
- + contactNo + ", address=" + address + "]";
- }
- */
- }
- ----------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement