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주차 미션 / 서버 1조 김경민 #16

Open
wants to merge 3 commits 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
53 changes: 50 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,59 @@ 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 name = ?, email = ?, password = ?, WHERE userId = ?;";
pstmt = con.prepareStatement(sql);
pstmt.setString(4, user.getUserId());
pstmt.setString(3, user.getPassword());
pstmt.setString(1, user.getName());
pstmt.setString(2, user.getEmail());
} 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;
try {
ArrayList<User> users = new ArrayList<>();
con = ConnectionManager.getConnection();
String sql = "SELECT userId, password, name, email FROM USERS";
pstmt = con.prepareStatement(sql);

rs = pstmt.executeQuery();

while(rs.next()) {
User user = new User(
rs.getString("userId"),
rs.getString("password"),
rs.getString("name"),
rs.getString("email"));
users.add(user);
}
return users;
} finally {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
if (con != null) {
con.close();
}
}
}

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