package tablaServlet;

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

import javax.servlet.http.HttpSession;

import m05bClasses.m05bConexion;
import m05bClasses.m05bFileLog;

/**
 * Inserte aquí la descripción del tipo.
 * Fecha de creación: (19/09/03)
 */
public class m05bGrabarTablaServlet 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) {

       	long lMatricula = 0;
       	String sTexto;
		java.sql.Connection conn=null;
		PreparedStatement pstmt = null;
       
       try

	{

		HttpSession session = request.getSession(true);
        lMatricula = Long.parseLong(request.getParameter("Codigo"));
        sTexto=request.getParameter("Descripcion");
		try{
			m05bConexion miConex = new m05bConexion();
			conn = miConex.getConnection();
			pstmt = conn.prepareStatement(
				"update	M0598T00 " + 
				"set	DESCRIP_98 = ?" + 
				"where	COD_TAB_98 = ?");
			pstmt.setString(1, sTexto);
			pstmt.setLong(2, lMatricula);
			pstmt.executeUpdate();

			response.sendRedirect("m05bTablasJsp.jsp?Codigo="+ lMatricula + "&Mensaje=true");
		} 	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);
		}
	}
}
}
