Demo entry 6734745

java

   

Submitted by anonymous on Apr 22, 2018 at 08:00
Language: Java. Code size: 908 Bytes.

package web;

import javax.servlet.*;
import javax.servlet.http.*;

import util.DBUtil;

import java.io.*;
import java.sql.*;
@SuppressWarnings("serial")
public class DelEmp extends HttpServlet{
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id=request.getParameter("id");
		//System.out.println("id:"+id);
		Connection conn=null;
		try{
			conn=DBUtil.getConnection();
			PreparedStatement prep=conn.prepareStatement("delete from t_emp where id=?");
			prep.setLong(1,Long.parseLong(id));
			prep.executeUpdate();
			response.sendRedirect("list");
		}catch(Exception e){
			e.printStackTrace();
			throw new ServletException(e);
		}finally{
			try{
				DBUtil.close(conn);
			}catch(Exception e){
				e.printStackTrace();
				throw new ServletException(e);
			}
		}		
	}	
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).