Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

Java servlet with jsp on sql server

Ads

 
 

Share on Google+Share on Google+

Ramkumar P
Java servlet with jsp on sql server
1 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners

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

Ads
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

<[email protected] 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

<[email protected] 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
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
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
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
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 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
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
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
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
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
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
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
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 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 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 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
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
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
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
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
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
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
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
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 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