package situacionesServlet;

import java.io.IOException;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpSession;

import m05bClasses.m05bConexion;
import m05bClasses.m05bFileLog;

public class m05bGrabarSituacionesServlet extends javax.servlet.http.HttpServlet{
    
	m05bFileLog miLog = new m05bFileLog();
	/**
 * Process incoming HTTP POST requests
 *
 * @param request Object that encapsulates the request to the servlet
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	performTask(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

	return super.getServletInfo();

}
/**
 * Initializes the servlet.
 */
public void init() {
	// insert code to initialize the servlet here

}
/**
 * Process incoming requests for information
 *
 * @param request Object that encapsulates the request to the servlet
 * @param response Object that encapsulates the response from the servlet
 */
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {

       String sCodigo;
       java.sql.Connection conn=null;
	   PreparedStatement pstmt = null;
       
       try

	{
		HttpSession session = request.getSession(true);

		sCodigo = request.getParameter("Codigo");

		try{
			m05bConexion miConex = new m05bConexion();
			conn = miConex.getConnection();
				pstmt = conn.prepareStatement(
					"insert into	M0542T00 " +
					"(SITUAC_42) " +
					" values " +
					"(?)" );
				pstmt.setString(1, sCodigo);
			    pstmt.executeUpdate();
			    response.sendRedirect("m05bRelSituacionesJsp.jsp");
		} catch (Exception SQLException) {
			miLog.addTraza(SQLException);
			response.sendRedirect("m05bError.jsp");
		} 	finally{
				if (pstmt != null)
					pstmt.close();
				if (conn != null)
					conn.close();
		}

	}
	catch(Throwable theException)
	{
		// uncomment the following line when unexpected exceptions
		// are occuring to aid in debugging the problem.
		miLog.addTraza(theException);
		try {
			response.sendRedirect("m05bError.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			miLog.addTraza(e);
		}
	}
}
}
