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()); 
    }
    %>









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
java and sql server NOT Mysql - JSP-Servlet
java and sql server NOT Mysql  Hi guys. Thank you all... was not properly answered. What I wanted was JSP CODE that can insert and retrieve image from MS SQL server NOT MySQL. Or is it not possible to do it in MS SQL server
Advertisements
java,sql - JSP-Servlet
java,sql  Hi Amardeep, Thank you from the bottom of my.... For read more information: http://www.roseindia.net/jsp/ Thanks.  ... any appreciable result. Unfortunately, my java coding skills are not as sharp
java sql - JSP-Servlet
java sql  I need to diplay only 10 records per page from my resultset. while(rs.next())loops through entire rs. How can I use a for loop... for more information. http://www.roseindia.net/jsp/ Thanks
Java servlet sql connectivity error - JSP-Servlet
Java servlet sql connectivity error  Hi, I have been trying to connect to sql database via the servlet program in java.I have not been successful so far. However when i try to connect to sql through a normal java program
jsp -sql - JSP-Servlet
jsp -sql  Hello Sir/Madam, Please send me the error in the following sql code if any. I did not get any error message and iam not getting...://www.roseindia.net/jsp/bank.shtml Thanks
java server programming : servlet - JSP-Servlet
java server programming : servlet  hi all, can you help check what's wrong with my servlet that i have a null pointer exception.Thanks ERROR... servlet request * @param response servlet response */ protected
SQL Query - JSP-Servlet
: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version...SQL Query   AS mysql backend updation query shows a syntax error
sql exception - JSP-Servlet
sql exception  Dear sir , I am working in a web-based project, In my system it is working fine but at client side getting the following exception so how to resolve this help me... java.sql.SQLException: ORA-28231
SQL error - JSP-Servlet
SQL error  Hello friends, Can we update a column with referrence to that column value. For example, the query ----------------------------------------------------------------------------- "update feedback set msgid
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
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
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
sql/xml query in jsp - JSP-Servlet
sql/xml query in jsp  Sir I am coding in jsp and trying to retrieve xml data from db2 using sql/xml query in jsp but getting no result. When running jsp file in browser the output
server side scripting java - JSP-Servlet
server side scripting java  I Very new to java server pages I am doing a project in java messaging service so in that i have a client on d server... on the server side i want that in the client side as pop up window
JSP with java/servlet - JSP-Servlet
(java bean or servlet) to fecth the database. Jsp would get the data from...JSP with java/servlet  Thanks Deepak for your answere to my previous.../servlet-jsp-data-list.shtml Hope that it will be helpful for you. Thanks
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
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 and Servlet - JSP-Servlet
JAVA JSP and Servlet  for sending mail through lan without intenet and also chatting facility for online users using Java JSP & SERVLET code.  Hi Friend, Please visit the following links: http://www.roseindia.net
sql/xml query in jsp - JSP-Servlet
sql/xml query in jsp  Sir Here is my code which is not working Testing JSP select id from "SYSTEM".PROFILE where xmlexists('$d[first="nitin"]' passing "SYSTEM".PROFILE.INFO as "d
server - JSP-Servlet
server - set the environment variable  How to set the environment variable in Java Servlet  Hi,To set the environment variables right click on the My Computer->properties- >advance->Environment Variables->
java servlet - JSP-Servlet
, Put servlet-api.jar into the lib folder of apache tomcat server. Thanks...java servlet  hi friends, Thanks in advance. Am poornima am created new servlet in eclipse its open but without including any code am getting
JAVA SERVLET - JSP-Servlet
JAVA SERVLET Log   Hi, A servlet file which create the log files ,then writing values to the list & log, we should have a thousand separator and no decimal values. This means instead of writing 986300.0 in the Log file
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
java,servlet,jsp - JSP-Servlet
java,servlet,jsp   i am doing a project on online examination system and in that there are problems that-- 1.i want to disable the back,forward and refresh button.Please give me the code for google crome browser. 2.suppose
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
Searching a word file on server in JSP - JSP-Servlet
Searching a word file on server in JSP  Seacrhing a word file on server side using JSP. I am Apache Tomcat Server. Please help me Sir
java jsp - JSP-Servlet
java jsp  i have a jsp file, in that i am uploading a file, after uploading the file had to display in the screen. it is displaying if only i refresh the page. but i want to display the uploaded file without refreshing the page
Java Servlet - JSP-Servlet
Java Servlet  3-tier structures of servlets
unable to connect to server - JSP-Servlet
-application-server/tomcat/install-configure.shtml Here you will get step by step installation and configuration of Apache Tomcat Server. After installation, create a web application folder inside the webapps folder and put the jsp file
java charts - JSP-Servlet
java charts  Hi,can any one tell me how to create dyanamic charts wrt database contents by 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
java - JSP-Servlet
java  how to upload a pdf file in a jsp page using servlet
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
server database connection - JSP-Servlet
server database connection  sir generally we will connect to the database by using the following steps 1.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver... the server while we are using client system.There we have to specify the "HOST STRING
java - JSP-Servlet
difference between Jsp and Servlet Jsp is better for view web pages, while servlet is good for request processing. Jsp has also all implicit objects... is done then servlet destroy() : that's the end of servlet. Jsp life cycle
Sun App Server - JSP-Servlet
Sun App Server  Dear Roseindia Team, I am Ragavendran.R.. I need to be clarified with a thing regarding J2EE1.4 Sun App server.. As everyone is aware, the web application can be executed using say http://localhost
Java compilation error - JSP-Servlet
are stored in database(sql), the file attachment also will be kept in the server...\Sema\org\apache\jsp\employee_005fupload_005fprofile_005fimage_jsp.java:9: package...\apache\jsp\employee_005fupload_005fprofile_005fimage_jsp.java:11: package
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
ascending or descending order in jsp using servlet - Java Server Faces Questions
ascending or descending order in jsp using servlet   My Problem is that how to sort any column in ascending or descending order,with following requirements 1. A single click on the header of a certain column causes
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
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
java  1.which class it extends when servlet is created automatically from jsp? 2. jsp get translated to servlet.where can find the servlet class (generetted from jsp)for tomcat?  Hi Friend, 1)It extends
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
Java - JSP-Servlet
Java  write a code to connect servlets-jsp page with sql database.  Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/connect-jsp-mysql.shtml http://www.roseindia.net/servlets
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
Java Mail - JSP-Servlet
Java Mail  hi, i refer ur J2EE Tutorial - Send Email From JSP & Servlet to send emails from my application.but when i run the jsp it will throw thhese exceptions. ERROR.....javax.mail.SendFailedException: Sending failed

Ads