Package com.jdbc.database
Class DB2024TEAM07_UserDAO
java.lang.Object
com.jdbc.database.DB2024TEAM07_UserDAO
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor that initializes the database connection. -
Method Summary
Modifier and TypeMethodDescriptionintadd(DB2024TEAM07_User user) Registers a new user by inserting a tuple into the DB2024_User table.intDeletes a user from the DB2024_User table.getOtherUser(String user_id) Retrieves the information of another user.Retrieves the information of the logged-in user.intAttempts to log in a user by verifying their credentials against the DB2024_User table.intupdate(DB2024TEAM07_User user, String pUser_id) Updates a user's information in the DB2024_User table.
-
Field Details
-
conn
-
pStmt
-
rs
-
-
Constructor Details
-
DB2024TEAM07_UserDAO
public DB2024TEAM07_UserDAO()Constructor that initializes the database connection.
-
-
Method Details
-
add
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
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
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
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
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
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
-