티스토리 뷰
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.springbook.biz.board.BoardVO;
import com.springbook.biz.common.JDBCUtil;
import com.springbook.biz.user.UserVO;
public class BoardDAO {
private Connection conn = null;
private PreparedStatement stmt = null;
private ResultSet rs = null;
private final String CREATE_BOARD = " CREATE TABLE BOARD ("
+ " SEQ INT(10) AUTO_INCREMENT PRIMARY KEY, TITLE VARCHAR(20), WRITER VARCHAR(20), CONTENT VARCHAR(50))";
private final String BOARD_INSERT = "INSERT INTO BOARD(TITLE, WRITER, CONTENT) VALUES(?,?,?)";
private final String BOARD_UPDATE = "UPDATE BOARD SET TITLE=?, CONTENT=? WHERE SEQ=?";
private final String BOARD_DELETE = "DELETE FROM BOARD WHERE SEQ=?";
private final String BOARD_GET = "SELECT * FROM BOARD WHERE SEQ=?";
private final String BOARD_LIST = "SELECT * FROM BOARD ORDER BY SEQ DESC";
public void insertBoard(BoardVO vo) {
System.out.println("===> JDBC insertBoard() ");
conn = JDBCUtil.getConnection();
try {
stmt = conn.prepareStatement(BOARD_INSERT);
stmt.setString(1, vo.getTitle());
stmt.setString(2, vo.getWriter());
stmt.setString(3, vo.getContent());
stmt.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
JDBCUtil.close(stmt, conn);
}
}
public List<BoardVO> getBoardList() {
BoardVO board = null;
List<BoardVO> boardList = new ArrayList<BoardVO>();
try {
System.out.println("===> JDBC로 getBoardList() 기능 처리");
conn = JDBCUtil.getConnection();
stmt = conn.prepareStatement(BOARD_LIST);
rs = stmt.executeQuery();
while(rs.next()) {
board = new BoardVO();
board.setTitle(rs.getString("TITLE"));
board.setWriter(rs.getString("WRITER"));
board.setContent(rs.getString("CONTENT"));
boardList.add(board);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return boardList;
}
}
|
cs |
'1. 자바' 카테고리의 다른 글
자바/이클립스/2020-05-24/ 톰캣 깨끗이 삭제 하기 (0) | 2020.05.24 |
---|---|
main-Map 4가지 (0) | 2020.05.24 |
이클립스에서 JRE 를 JDK 로 변환하기 (0) | 2020.05.24 |
Txt: is-a 관계와 has-a 관계의 비교 (0) | 2020.05.24 |
SpringBoot H2 JDBC 설정 시 주의할 점 @hawaii-boot-mybatis pjt40 (0) | 2020.05.24 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- React
- maven
- JUnit
- Mlearn
- mariadb
- COLAB
- KAFKA
- Eclipse
- AWS
- jQuery
- ERD
- SpringBoot
- vscode
- Python
- tensorflow
- JPA
- database
- Django
- docker
- Git
- Java
- nodejs
- SQLAlchemy
- Algorithm
- springMVC
- Oracle
- Mongo
- intellij
- FLASK
- terms
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
글 보관함