package idc.service.command;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import idc.model.*;

public class IdcVpnWriteForm implements IdcCmd{
	
	IdcDAO dao = new IdcDAO();
	
	//vpn등록창 정보 불러오기
	public void execute(HttpServletRequest request, HttpServletResponse response){
		String client_code = request.getParameter("client_code");
		request.setAttribute("client_code", client_code);
		
		Date curdate = getCurdate();
		request.setAttribute("curdate", curdate);
	}
	
	private Date getCurdate(){
		Date curdate = null;
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;		
		
		try {
			conn = dao.getConn();
			String sql = "SELECT curdate() AS curdate FROM serverDB";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			
			if(rs.next()){
				curdate = rs.getDate("curdate");
			}			
						
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			try {
				if(rs != null) rs.close();
				if(pstmt != null) pstmt.close();
				if(conn != null) conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return curdate;
	}

}
