Class DB2024TEAM07_UserDAO

java.lang.Object
com.jdbc.database.DB2024TEAM07_UserDAO

public class DB2024TEAM07_UserDAO extends Object
This class provides a Data Access Object (DAO) for managing users in a database. It offers methods for user registration, login, information modification, retrieval, and deletion.
  • Field Details

  • Constructor Details

    • DB2024TEAM07_UserDAO

      public DB2024TEAM07_UserDAO()
      Constructor that initializes the database connection.
  • Method Details

    • add

      public int add(DB2024TEAM07_User user)
      Registers a new user by inserting a tuple into the DB2024_User table.
      Parameters:
      user - The DB2024TEAM07_User object representing the new user to be registered.
      Returns:
      The number of rows affected by the INSERT operation. This should be 1 if the registration was successful. Returns -2 if an error occurs during registration.
    • signIn

      public int signIn(String user_id, String user_pw)
      Attempts to log in a user by verifying their credentials against the DB2024_User table.
      Parameters:
      user_id - The user's ID.
      user_pw - The user's password.
      Returns:
      1 if the login is successful (user ID exists and password matches). 0 if the login fails due to an incorrect password (user ID exists but password doesn't match). -1 if the login fails due to a non-existent user ID. -2 if an error occurs during the login process.
    • update

      public int update(DB2024TEAM07_User user, String pUser_id)
      Updates a user's information in the DB2024_User table.
      Parameters:
      user - The DB2024TEAM07_User object containing the updated information.
      pUser_id - The previous user ID of the user whose information is being updated.
      Returns:
      The number of rows affected by the UPDATE operation. This should be 1 if the update was successful. Returns -2 if an error occurs during the update process.
    • getUser

      public DB2024TEAM07_User getUser(String user_id)
      Retrieves the information of the logged-in user.
      Parameters:
      user_id - The ID of the logged-in user.
      Returns:
      A DB2024TEAM07_User object containing the user's information, or null if the user is not found.
    • getOtherUser

      public DB2024TEAM07_UserVO getOtherUser(String user_id)
      Retrieves the information of another user.
      Parameters:
      user_id - The ID of the user whose information is being retrieved.
      Returns:
      A DB2024TEAM07_UserVO object containing the user's basic information (ID, name, location), or null if the user is not found.
    • delete

      public int delete(String user_id, String user_pw)
      Deletes a user from the DB2024_User table. The user must enter their password to confirm the deletion.
      Parameters:
      user_id - The ID of the user to be deleted.
      user_pw - The password of the user to be deleted.
      Returns:
      1 if the deletion is successful. 0 if the deletion fails due to an incorrect password. -1 if the deletion fails due to a non-existent user ID. -2 if an error occurs during the deletion process.
    • getAllUsers

      public List<DB2024TEAM07_User> getAllUsers()