Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6주차 미션 / 서버 2조 강상민 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions src/main/java/core/dao/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,63 @@ public void insert(User user) throws SQLException {
}

public void update(User user) throws SQLException {
// TODO 구현 필요함.
Connection con = null;
PreparedStatement pstmt = null;

try {
con = ConnectionManager.getConnection();
String sql = "UPDATE USERS SET password = ?, name = ?, email = ? WHERE userId = ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, user.getPassword());
pstmt.setString(2, user.getName());
pstmt.setString(3, user.getEmail());
pstmt.setString(4, user.getUserId());

pstmt.executeUpdate();
} finally {
if (pstmt != null) {
pstmt.close();
}
if (con != null) {
con.close();
}
}
}

public List<User> findAll() throws SQLException {
// TODO 구현 필요함.
return new ArrayList<User>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
List<User> userList = new ArrayList<>();

try {
con = ConnectionManager.getConnection();
String sql = "SELECT * FROM USERS";
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();

while (rs.next()) {
String userId = rs.getString("userId");
String password = rs.getString("password");
String name = rs.getString("name");
String email = rs.getString("email");

User user = new User(userId, password, name, email);
userList.add(user);
}
} finally {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
if (con != null) {
con.close();
}
}

return userList;
}

public User findByUserId(String userId) throws SQLException {
Expand Down
Binary file modified webapp/WEB-INF/classes/core/dao/UserDao.class
Binary file not shown.