Created
October 2, 2013 10:33
-
-
Save swapnil-webonise/6791759 to your computer and use it in GitHub Desktop.
Deleting Record From Database Using Servlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examadmin; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.sql.Connection; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.util.StringTokenizer; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
public class deleteAttribute extends HttpServlet | |
{ | |
private static final long serialVersionUID = 1L; | |
Connection conn; | |
ResultSet rs,rs1; | |
PreparedStatement ps,ps1,ps2; | |
public deleteAttribute() | |
{ | |
super(); | |
conn=ExamConnection.getConnection(); | |
System.out.println("Conection successfull"); | |
} | |
public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | |
{ | |
try | |
{ | |
PrintWriter out = response.getWriter(); | |
int cnt=0; | |
String deleteQuery=""; | |
String totalAttribute = request.getParameter("totalAttribute"); | |
String planId = request.getParameter("planId"); | |
StringTokenizer st1 = new StringTokenizer(totalAttribute,"$"); | |
while (st1.hasMoreTokens()) | |
{ | |
deleteQuery = " delete from kpa_plan_attribute where Kpa_Plan_Id=? and kpa_attribute=? "; | |
ps = conn.prepareStatement(deleteQuery); | |
ps.setInt(1, Integer.parseInt(planId)); | |
ps.setInt(2, Integer.parseInt(st1.nextToken())); | |
cnt+=ps.executeUpdate(); | |
} | |
out.print(cnt); | |
} | |
catch(Exception se) | |
{ | |
System.out.println("Exception: "+se); | |
} | |
} | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | |
{ | |
this.process(request,response); | |
} | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | |
{ | |
this.process(request,response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment