[Spring] - Spring JDBC Template (3) : insert update, delete 처리
○ Spring JDBC Template (3) : insert update, delete 처리 |
insert, update, delete를 사용할 때 template.update() 를 쓴다 private void upHit(final String bId) { String query = "update mvc_board set bHit = bHit + 1 where bId = ?"; this.template.update(query, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, Integer.parseInt(bId)); } }); } public void modify(final String bId, final String bName, final String bTitle, final String bContent) { String query = "update mvc_board set bName = ?, bTitle = ?, bContent = ? where bId = ?";
this.template.update(query, new PreparedStatementSetter() {
@Override public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, bName); ps.setString(2, bTitle); ps.setString(3, bContent); ps.setInt(4, Integer.parseInt(bId)); } });
}
public void delete(final String bId) { String query = "delete from mvc_board where bId = ?";
this.template.update(query, new PreparedStatementSetter() {
@Override public void setValues(PreparedStatement ps) throws SQLException { ps.setString(1, bId); } }); } public int upHit(String articleNumber) { return jdbcTemplate.update("UPDATE bbs SET hit = hit + 1 WHERE article_number = ?", articleNumber); }
public int loginCheck(String id, String pw) { String result = jdbcTemplate.queryForObject("SELECT pw FROM users WHERE id = ?", new Object[]{id}, String.class); int loginStatus = 0;
if(result != null && result != "") { if(pw.equals(result)) loginStatus = LoginStatus.LOGIN_SUCCESS; else loginStatus = LoginStatus.PASS_FAIL; } else loginStatus = LoginStatus.NOT_MEMBER;
return loginStatus; }
public int insertArticle(BBSDto article) { return jdbcTemplate.update("INSERT INTO bbs VALUES(bbs_seq.nextval, ?, ?, ?, bbs_seq.currval, 0, 0, 0, sysdate, ?)", article.getId(), article.getTitle(), article.getContent(), article.getFileName()); }
public int upPos(int groupId, int pos) { return jdbcTemplate.update("UPDATE bbs SET pos = pos + 1 WHERE group_id = ? AND pos > ?", groupId, pos); }
public int replyArticle(BBSDto article) { this.upPos(article.getGroupId(), article.getPos());
return jdbcTemplate.update("INSERT INTO bbs VALUES(bbs_seq.nextval, ?, ?, ?, ?, ?, ?, 0, sysdate, ?)", article.getId(), article.getTitle(), article.getContent(), article.getGroupId(), article.getDepth() + 1, article.getPos() + 1, article.getFileName()); }
public int updateArticle(BBSDto article) { return jdbcTemplate.update("UPDATE bbs SET title=?, content=? WHERE article_number=?", article.getTitle(), article.getContent(), article.getArticleNumber()); }
public int deleteArticle(String articleNumber) { return jdbcTemplate.update("DELETE FROM bbs WHERE article_number = ?", articleNumber); } |
참조 : http://bigfat.tistory.com/91,
https://www.youtube.com/watch?time_continue=2257&v=bEQJ4paS3G4 (Seoul Wiz)
'Spring' 카테고리의 다른 글
[Spring] - Spring Security (2) : IN-Memory 로그인 인증 (0) | 2018.07.25 |
---|---|
[Spring] - Spring Security (1) : 보안 관련 설정하기 (0) | 2018.07.25 |
[Spring] - Spring JDBC Template (2) : select 처리 (0) | 2018.07.24 |
[Spring] - Spring JDBC == JDBC (1) Template 사용하기 위한 설정 (0) | 2018.07.18 |
[Spring] - 오라클 연동 시 HTTP Status 500 - Servlet.init() for servlet appServlet threw exception 에러 (0) | 2018.07.18 |