1. BoardDao.get() : 게시글 세부조회 기능
public Board get(Long bno) {
Board board = null;
try {
//클래스 로드
Class.forName("oracle.jdbc.driver.OracleDriver");
// connection 취득
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe",
"odoung", "1234");
// 문장 생성
String sql = "UPDATE TBL_BOARD SET\r\n" +
"HITCOUNT = HITCOUNT + 1\r\n" +
"WHERE BNO = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
// 파라미터 바인딩
pstmt.setLong(1, bno);
// 문장 실행(반영)
pstmt.executeUpdate();
// 문장 생성
sql = "SELECT BNO, TITLE, CONTENT, HITCOUNT,\r\n" +
" CASE\r\n" +
" WHEN SYSDATE - REGDATE > 1 THEN TO_CHAR(REGDATE, 'YY/MM/DD')\r\n" +
" ELSE TO_CHAR(REGDATE, 'HH24:MI:SS')\r\n" +
" END REGDATE,\r\n" +
" WRITER\r\n" +
"FROM TBL_BOARD\r\n"
+ "WHERE BNO = ?\r\n"
+ "ORDER BY 1 DESC";
pstmt = conn.prepareStatement(sql);
pstmt.setLong(1, bno);
// 결과집합 생성
ResultSet rs = pstmt.executeQuery();
// 결과집합 순회 후 데이터 바인딩
while(rs.next()) {
int idx = 1;
board = new Board(rs.getLong(idx++), rs.getString(idx++), rs.getString(idx++),
rs.getInt(idx++), rs.getString(idx++), rs.getString(idx++));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return board;
}