Riucc's Storage
RSS
태그
관리
쓰기
카테고리
  • IT (593)
    • 정리 (0)
    • C# (42)
    • ASP.NET MVC (16)
    • JQuery&Javascript (12)
    • CSS (11)
    • 데이터베이스 (32)
    • Windows Server (6)
    • Active Directory (3)
    • Exchange (9)
    • JAVA (2)
    • JSP (39)
    • JSP 게시판 만들기 (21)
    • JSP 개발 참고 (15)
    • JSP 안드로이드 (4)
    • Servlet (17)
    • Spring (42)
    • HTML (14)
    • NodeJS (46)
    • MongoDB (11)
    • 리눅스 (18)
    • 자료구조 (16)
    • 아이폰 (24)
    • 안드로이드 (68)
    • API 활용하기 (10)
    • 소켓네트워크 (28)
    • 라즈베리파이 (11)
    • AWS클라우드 (10)
    • 빅데이터Hadoop (22)
    • 커널모듈프로그래밍 (8)
    • 기타 (10)
    • 자격증 (26)
Riucc's Storage

[Spring] - Spring JDBC Template (3) : insert update, delete 처리

Spring|2018. 7. 24. 16:04
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

○ 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

댓글()
카테고리
  • IT (593)
    • 정리 (0)
    • C# (42)
    • ASP.NET MVC (16)
    • JQuery&Javascript (12)
    • CSS (11)
    • 데이터베이스 (32)
    • Windows Server (6)
    • Active Directory (3)
    • Exchange (9)
    • JAVA (2)
    • JSP (39)
    • JSP 게시판 만들기 (21)
    • JSP 개발 참고 (15)
    • JSP 안드로이드 (4)
    • Servlet (17)
    • Spring (42)
    • HTML (14)
    • NodeJS (46)
    • MongoDB (11)
    • 리눅스 (18)
    • 자료구조 (16)
    • 아이폰 (24)
    • 안드로이드 (68)
    • API 활용하기 (10)
    • 소켓네트워크 (28)
    • 라즈베리파이 (11)
    • AWS클라우드 (10)
    • 빅데이터Hadoop (22)
    • 커널모듈프로그래밍 (8)
    • 기타 (10)
    • 자격증 (26)
최근 등록 현황
최근 글
최근 월별 글
최근 댓글
최근 글
최근 월별 글
최근 댓글
최근 글
최근 월별 글
최근 댓글
달력
지난달
2025.7
다음달
일월화수목금토
12345
6789101112
13141516171819
20212223242526
2728293031
태그 구름
  • 정보처리산업기사 총정리
  • 안드로이드 카카오 로그인 연동
  • 데이터베이스
  • 정규형
  • 정보처리산업기사 필기 정리
  • 정보처리산업기사 15년 필기
  • 정규화
  • 자료구조
  • 정보처리산업기사 15년
  • 정보처리산업기사 16년
  • jsp
  • 이클립스 디비 연동
  • HTML
  • 안드로이드 카카오 로그인
  • 이클립스 mysql 연동
  • nodejs express
  • 정보처리산업기사 요약
  • 카카오 로그인 연동
  • 안드로이드
  • 정보처리산업기사 필기
  • 소켓 프로그래밍
  • 정보처리기사 실기 정리
  • 정보처리산업기사 정리
  • 안드로이드 intent
  • 정보처리산업기사 16년 필기
  • 소켓
  • nodejs MySQL 연동하기(Connection Pool)
  • 카카오 로그인
  • 리눅스
  • 커널 모듈 프로그래밍
카운터
전체 방문자
오늘
어제
Skin by M1REACT. Designed by M1STORY.TISTORY.COM. Valid XHTML 1.0 and CSS 3. Copyright ⓒ Riucc's Storage. All rights reserved.

티스토리툴바