Home Answers Viewqa JSP-Servlet How to delete the row from the Database by using while loop in servlet

 
 


Ramanjaneyulu Manam
How to delete the row from the Database by using while loop in servlet
1 Answer(s)      2 years and 2 months ago
Posted in : JSP-Servlet

Dear Sir/Madam,

I am trying to delete the one user data in the Oracle SQL server database by using Servlet program (Tomcat server).

In Database table have 6 users details are there.

Table name is â??JDUSERâ?? and columns are USERS (Char), PASS (Varchar2) and CODE (Varchar2). I am trying to delete 4th user details.

While loop is not terminate, in while loop why If condition not working it checking until end of the table and gives else black statement. So what is my mistake and please give the solution to me.

My HTML code is:

<html>
<title> Delete Page</title>
  <form action="JdbcDeleteServlet" method="post">
    <center><font color='red'>
     <h2> Remove Data</h2><br/></font>
        User Name : <input type="text" name="uname" ><br/><br/>
        Password : <input  type="password" name="pwd"><br/><br/>
        Verification code : <input type="text" name="code"><br/><br/>
        <input type="submit" value="Delete"/>
    </center>
  </form>
</html>


My Database table is:

My JavaServlet Program is:

import java.lang.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class JdbcDeleteServlet extends HttpServlet
{
    String dbn,dbp,dbco;
    String un,up,uco;
    boolean flag=false;
    public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
    {
        try
        {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            response.setContentType("text/html");
            un=request.getParameter("uname");
            up=request.getParameter("pwd");
            uco=request.getParameter("code");
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection c=DriverManager.getConnection("jdbc:odbc:hari","raman","raman");
            Statement s=c.createStatement();
            s.execute("select *from jduser");
            ResultSet rs=s.getResultSet();
            while(rs.next())
              {
                  dbn=rs.getString("users");
                  dbp=rs.getString("pass");
                  dbco=rs.getString("code");
                  if(un.equals(dbn)&&up.equals(dbp)&&uco.equals(dbco))          // another formate  if((un==dbn)&&(up==dbp)&&(uco==dbco))
                    {
                        s.executeUpdate("delete jduser where users='"+un+"'");
                        flag=true;
                        break;
                    }
              }
              if(flag==true)
                out.println("<font color=green>"+dbn+" user Data deleted successfully");
              else
                out.println("<font color=red>Sorry "+un+" user data is Not Available");
            s.close();
            c.close();
            out.close();
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
        catch(SQLException e)
        {
            System.out.println(e.getMessage());
        }
        catch(ClassNotFoundException e)
        {
            System.out.println(e.getMessage());
        }
    }
}

So finally where is my mistake and in while loop why if loop not working. please give me solution. It is Urgent...

View Answers

May 18, 2011 at 6:52 PM


When you retrieve the data from the Database by using Servlet (JDBC). you entered 'ramanujan' is 9 character but in the database 'ramanujan ' is 15 characters because remaining letters it consider as spaces so you use trim() then spaces are trimmed. it will working good.

trim( )

The trim( ) method returns a copy of the invoking string from which any leading and trailing whitespace has been removed. It has this general form:

String trim( )

Here is an example:

String s = "    Hello World    ".trim();

This puts the string â??Hello Worldâ?? into s.

while(rs.next())
       {
                  dbn=rs.getString("users");
                  dbp=rs.getString("pass");
                  dbco=rs.getString("code");
                   dbn=dbn.trim();
                   dbp=dbp.trim();
                   dbco=dbco.trim();
                  if(un.equals(dbn)&&up.equals(dbp)&&uco.equals(dbco))  
                    {
                        s.executeUpdate("delete jduser where users='"+un+"'");
                        flag=true;
                        break;
                    }
        }









Related Pages:
How to delete the row from the Database by using while loop in servlet
How to delete the row from the Database by using while loop in servlet ... server database by using Servlet program (Tomcat server). In Database table.... It is Urgent...  When you retrieve the data from the Database by using
How to delete the row from the Database by using servlet
How to delete the row from the Database by using servlet  Dear Sir...: Delete row from database using servlet   In that link solution... then the user data to be delete from the database table. Assume in Database table have
Delete a row from database by id
Delete a row from database by id  I m creating a small application using servlet. There is a form (index.jsp)having 10 fields on submitting the form...) for "DELETE" AND "UPDATE". On clicking delete which is hyper link that particular row
delete row
delete row  how to delete row using checkbox and button in php...("sourabh", $link); $rows=mysql_query("select * from sonu"); $row=mysql...;/tr> <?php while($row=mysql_fetch_array($rows)) { ?> <tr>
sqlite database delete row
sqlite database delete row  How to delete row from SQLite Database?    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM aListDB WHERE id='%@'",details.ids
delete
delete  how delete only one row in the database using jsp.database... = conn.createStatement(); st.executeUpdate("DELETE FROM employee WHERE empid...); String query = "select * from employee"; st = con.createStatement
delete multiple row using checkbox
delete multiple row using checkbox  delete multiple row using... fields bookid,author and title in the database. 1) Create book.jsp <%@page...=null; st=conn.createStatement(); rs = st.executeQuery("select * from book"); int
JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from.... 6. Finally call deleteRow() ResultSet method for delete the current row form
delete multiple row using checkbox
delete multiple row using checkbox  how to delete multiple row in a table which is connected to database using checkbox
delete multiple row using checkbox
delete multiple row using checkbox  how to delete multiple row in a table which is connected to database using checkbox
Delete a Specific Row from a Database Table
Delete a Specific Row from a Database Table   ..., and in this section we are going to do the same that is, how to delete a specific row... the connection we are going to delete a specific row from the table. If the row
Count Row - JSP-Servlet
Count Row  Hello all, Please I need your help on how to desplay the number of row(s) affected along with the affected row(s) in mssql database 2000 using java servlet and html form. Thanks for your good job!   Hi friend
Delete row and column from table through java code
will see how to delete row and column from given table through java code. Java code... Delete row and column from table through java code...) from stu_info"); rs.next(); // This sql query delete the row having
Using while loop to loop through a cursor
Using while loop to loop through a cursor  ... while loop to loop through a cursor'. The Example create a table Stu_Table... that establish the result set. The While loop check a condition
delete an item from database
delete an item from database  how to delete an item from the database using jsp
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery...()); } } } this is the code m using . Error is -query must begin with SELECT or FROM
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
delete row from a table using hibernate
delete row from a table using hibernate  //code in java file String hql="delete from CONTACT c where ID=6"; Query query=session.createQuery... [delete from CONTACT] int i=query.executeUpdate
how to delete a row in sql without using delete command.
how to delete a row in sql without using delete command.  how to delete a row in sql without using delete command. thanks in advance
Hibernate delete a row error - Hibernate
Hibernate delete a row error  Hello, I been try with the hibernate delete example (http://www.roseindia.net/hibernate/hibernate-delete.shtml...(); //======================================= sess = fact.openSession(); String hql = "delete from Contact contact
delete record
delete record  how to delete record using checkbox and button in php... deleted from the database. In the database we have created three fields bookid...=conn.createStatement(); rs = st.executeQuery("select * from book"); int i=0; while
While loop Statement.
While loop Statement.   How to Print Table In java using While Loop
JDBC Delete Row In Table Example
JDBC Delete Row In Table Example : In this tutorial we will learn how delete specific row from the table use mysql JDBC driver.This tutorial defined how one or more specific  row delete from table that follow any given condition
How to insert or delete records in MS access database using jsp - JSP-Servlet
How to insert or delete records in MS access database using jsp  Hi friends please provide me a solution that i insert or delete record from a database using java server pages. I used the microsoft access 2003 database. PlZ
Deleting a Row from SQL Table Using EJB
are going to delete a row from the SQL Table. Find out the steps given below that describes how to delete a particular row from the database table using EJB... Deleting a Row from SQL Table Using EJB
Deleting a Row from SQL Table Using EJB
to delete a row from the SQL Table. Find out the steps given below that describes how to delete a particular row from the database table using EJB. The steps... Deleting a Row from SQL Table Using EJB   
Deleting row and column from a table
Deleting row and column from a table  In this program ,we delete row... connection interface and java driver. After it we can delete row using "delete... the row having minimum ID.  statement.executeUpdate("delete from cellular where id
Arraylist from row values
Arraylist from row values  Hello, can anyone please help on how to make an arraylist from the row values of a particular column from a database...("select * from employee"); ArrayList<String> list=new ArrayList<
While loop Statement
While loop Statement  How to print a table using while loop?   The given example displays the multiplication table of the given number... +" = "); while(y<=10) { int t = x
while loop to for loops
while loop to for loops  I have to change this while loops... to know how to change it. int currentNum= num1; while(num1>num2...("%-10s%-10s%n", "------","------"); //while loop to output 1- 10
Delete and add row from Table View iPhone
Delete and add row from Table View iPhone In this tutorial will learn how to delete and also how to add row into the table view iPhone, with the help of edit... used earlier using reloadData method and in DeleteButtonAction will delete object
Using while loop to loop through a cursor
Using while loop to loop through a cursor  ... while loop to loop through a cursor'. The Example create a table Stu_Table... that establish the result set. The While loop check a condition and executes
How to delete and update from Jtable cell in swing app
How to delete and update from Jtable cell in swing app  Hii Sir... the database . I want to remove and delete the same row which is selected for the dletion... on delete button on selecting particular row which has to be deleted then last row
to display single row from database and next to display other question - JSP-Servlet
to display single row from database and next to display other question  Hi all, I am using JSP with MYSQL backend. In my project we have 100 questions in database we have to display first question on clicking the button
How to update,Delete database values from jtable cells ..
How to update,Delete database values from jtable cells ..  hello Sir... from database into jtable of a jpanel.. Now Sir, According to my need i have... to a particular cell will be updated into database and if we want to delete
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... the problem   Get data from database using servlet Retrieve data from database using JSP Get data from database using JSP
how to display a table from database using servlet
how to display a table from database using servlet  how to display a table with values from servletpage   Hi Friend, Please go through the following link: http://roseindia.net/jsp/servlet-jsp-data-list.shtml Thanks
Delete a Column from a Database Table
Delete a Column from a Database Table   ... to delete a column from a database table. We are not going to create a new table... the already created table in the specific database. Now if we want to delete
how to delete specified coloumn from database(MS Access) by using windows application
how to delete specified coloumn from database(MS Access) by using windows application  how to delete specified coloumn from database(MS Access) by using c# windows application
JDBC: Delete Record using Prepared Statement
JDBC: Delete Record using Prepared Statement In this section, we will discuss how to delete row of a table using Prepared Statements. Delete Record ... statement. You can delete any specific record under some condition using WHERE
Hibernate Delete Query
; In this lesson we will show how to delete rows from the underlying database using the hibernate. Lets first write a java class to delete a row from... (DeleteHQLExample.java), which we will delete a row from the insurance table using the query
how to make enable/disable textbox in while(rs.next)
how to make enable/disable textbox in while(rs.next)  Hi, I'm trying to enable/disable the textbox in the while loop. It works but when i want.../disable function,the data are updated correctly. Is my javascript wrong? How do i
how to make enable/disable textbox in while(rs.next)
how to make enable/disable textbox in while(rs.next)  Hi, I'm trying to enable/disable the textbox in the while loop. It works but when i want.../disable function,the data are updated correctly. Is my javascript wrong? How do i
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
Update delete perticular row from brower on link - Struts
Update delete perticular row from brower on link   how can update and delete perticular row from List of employee in brower format are ramesh... page with textbox update , if delete click then that row also delete from
how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row
or .txt) file and get the values from that file and store them into database...how to read the values for text and csv files and store those values into database in multiple rows..means one value for one row  Hai, I need
Deleting Mysql Clob data using servlet
Deleting  Mysql Clob data using servlet In this Section, we will discuss about how to delete a Clob data from a database table using servlet. A CLOB... such as HTML. CLOB values are not stored as a part of the row of the database
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
delete data from database - SQL
delete data from database  HOw to delete specific data from table> I want to delete one record from database. Thnx  Hi friend, -------------------------------------------- Visit for more information
How to Extract row from table view using JSP Code - Java Beginners
How to Extract row from table view using JSP Code  Hi Friends... problem exist with retrival of row from a table on click of link. Table Structure... Email 1 A B C D E F G Update Delete On click of Update, entire row

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.