Java servlet with jsp on sql server

Java servlet with jsp on sql server

How to delete a user by an admin with check box in Java Servlet with jsp on Sql Server?

View Answers

October 3, 2012 at 3:55 PM

Here is a jsp example that can delete the multiple record from the database by selecting checkbox.In the given code, we have specified only three fields bookid,author and title in the database.

1) Create book.jsp

<%@page import="java.sql.*"%>

<form name=myname method=post action="delete.jsp">
<table border="1">
<tr><td></td>
<td><b><u>bookid</u></b></td>
<td><b><u>Author</u></b></td>
<td><b><u>title</u></b></td>
</tr>
<%try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from book");
int i=0; while(rs.next()){ %>
<tr><td><input type="checkbox" name="check<%=i%>" value=<%= rs.getString("bookid") %>></td>
<td><%= rs.getString("bookid") %></td>
<td><%= rs.getString("author") %></td>
<td><%= rs.getString("title") %></td>
</tr><%
i++;
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>
<input type="submit">
</form>

2) Create delete.jsp

<%@page import="java.sql.*"%>

<%String id[]= new String[10];
for(int i=0;i<10;i++){
id[i]=request.getParameter("check"+i);
out.println(id[i]);
}
%>
<%try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
for(int a=0;a<10;a++){
st.executeUpdate("delete from book where bookid='"+id[a]+"'");

}
}catch(SQLException e){ 
    System.out.println(e.getMessage()); 
    }
    %>

Ads









Related Tutorials/Questions & Answers:
Java servlet with jsp on sql server
Java servlet with jsp on sql server  How to delete a user by an admin with check box in Java Servlet with jsp on Sql Server?   Here is a jsp example that can delete the multiple record from the database by selecting
server-jsp - JSP-Servlet
server-jsp  how can we implement a simple database(ms access) for storing information about the HTTP requests sent to a web server(database
Advertisements
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
jsp sql server 2005 connectivity
jsp sql server 2005 connectivity  your jsp mysql tutorial is very help full.Please tell me how to connect jsp with SQL server 2005
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
java servlet programming - JSP-Servlet
java servlet programming  i want 2 insert the date time into the sql column of data type datetime through servlets dynamically .How 2 do dat
java servlet programming - JSP-Servlet
java servlet programming  when i m inserting an image file into the sql table in a column of data type binary using prepared statement... 0xFFD8FFE000104A46494600010200006400640000FFFE001241646F6265.....in the sql table .how to display the filename
java - JSP-Servlet
java  what is the difference between jsp and servlet?   Hi firend, Main difference between Jsp and Servlet Jsp is better for view web pages, while servlet is good for request processing. Jsp has also all
java servlets - JSP-Servlet
java servlets  how to get the parameter value of input type file using java servlets  Hi, You can use request.getParameter(). In Jsp, --- --- IN servlet, String fileName=request.getParameter('fl'); If you
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets the ServletContextAttributeListener interface. I am overriding all three methods, but in the attributeReplaced() method, i want to perform a redirect to another servlet
Java - JSP-Servlet
;Run As->Run On Server. These options you have to select to run the servlet..... This is a general question. How to compile a servlet program? I need step by step explaination.. MoreOver,I know JAVA to some extent.. But I need to improve my
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
compiling a uploaed java file - JSP-Servlet
compiling a uploaed java file  How a uploaded java source file is automatically compiled(i.e converted to .class file) in server using jsp/servlet
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in jsp
How Run JSP in Apache TomCat Server? - JSP-Servlet
How Run JSP in Apache TomCat Server?  How to Run JSP in Apache Tomcat Server? I have getting Jasper Exception which says class not found i have pasted my hello world example of JSP in the Jsp-example directory. and tried. 
java beans - JSP-Servlet
java beans  how to get the values from this page to java page bcoz i want to insert these values into table... the problem visit to : http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks
core java - JSP-Servlet
core java  Thank you very much for your fast reply.. Now it is working... In my project I have to insert the data from different JSP pages. I know... to dbase,Update,insert,delete functions to the different JSP pages. From ur JSP page
image uploading perminssion in server - JSP-Servlet
problem image uploading in server that i working fine in my system, OS Ubuntu. but in server it is showing following error...) com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:89) org.apache.jsp.jsp.BSAdminProductsCreate_jsp
java - JSP-Servlet
dealing with JAVA platform with its addresses.. Think me as your friend (ONLY
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
jsp servlet hosting
jsp servlet hosting  Hi, What is jsp servlet hosting? Thanks   In case of jsp servlet hosting, hosting companies are providing hosting environment where client can host Java based web application on the server
Servlets vs JSP - JSP-Servlet
and servlet act as a controller. 2)JSP pages contain a mixture of HTML, Java scripts, JSP elements, and JSP directives while servlet is totally uses java code. 3)Java Server Pages is that they are document-centric. Servlets, on the other hand
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
JDBC Connection code to connect servlet with SQL Server 2008
JDBC Connection code to connect servlet with SQL Server 2008  Please ans me why it is not connect i use netbeans IDE7.0 Jdk 1.7 i also add sqljdbc4.jar but the output is SEVERE: Java Runtime Environment (JRE) version 1.6
how to include a java class in jsp - JSP-Servlet
how to include a java class in jsp  hello sir, this is my first question, i want know that how to use a java class function's variables and methods of a java class in jsp.if possible plz tr to explain with a simple example
Java to SQL Server Connectivity
Java to SQL Server Connectivity  Hi, heres my code private void bookedButton() { try { Class.forName... with sql server connectivity at the background to save the data. Now, after
Servlet - JSP - JSP-Servlet
Servlet - JSP  Here is my complete code. all my code is running with out any error. the for loop in servlet is running as many times as my checkboxes... Servlet Code: ---------------------- package com.servlet; import
how to insert array data into sql server using jsp
how to insert array data into sql server using jsp  hello, i have problem to insert array data into my sql server from jsp form. beloW is my code... from form, but not insert into my sql database. try { //String
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need

Ads