[JSP] 간단 세션 카운터

String SQL = null;

Connection conn = null;
PreparedStatement pstmt0 = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

conn = dataSource.getConnection();

try {

/**/
//세션값에 의한 카운터 증가 (단점: 접속량이 많으면 서버에 부하가 발생할 수도 있음, 로그아웃후, 로그인후 다시 카운트)
//각게시판, 각게시물 세션저장 (부하가 클 수 있음)
String sessionid=(String)session.getAttribute("SESSIONID"+S_TABLE+seq);

if(sessionid == null) {
//@@@@session.setAttribute("sessionid",session.getId());
session.setAttribute("SESSIONID"+S_TABLE+seq, LOGONSESSION.getMid()); //사용자아이디체크

SQL = "UPDATE db."+S_TABLE+" SET db."+S_TABLE+".CNT=CNT+1 WHERE db."+S_TABLE+".SEQ=?";

pstmt0 = conn.prepareStatement(SQL);
pstmt0.setInt(1, seq);

pstmt0.executeUpdate();

pstmt0.close();
pstmt0 = null;

}

} // end of try
catch(SQLException sqle) {
out.write("SQL 처리 도중 오류발생 :
");
out.print(sqle);
out.write("
");
}
finally {
try { if(rs != null) rs.close(); } catch(SQLException e) {}
try { if(pstmt0 != null) pstmt0.close(); } catch(SQLException e) {}
try { if(pstmt != null) pstmt.close(); } catch(SQLException e) {}
try { if(conn != null) conn.close(); } catch(SQLException e) {}
rs = null;
pstmt0 = null;
pstmt = null;
conn = null;
}

댓글

이 블로그의 인기 게시물

[LINUX] CentOS 부팅시 오류 : UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY

[MSSQL] 데이터베이스가 사용 중이어서 배타적으로 액서스할 수 없습니다

구글코랩) 안전Dream 실종아동 등 검색 오픈API 소스를 공유합니다. (구글드라이브연동, 이미지 수집 소스)