[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 처리 도중 오류발생 :
}
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;
}
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;
}
댓글