Deleting from database - Done so far


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Deleting from database - Done so far

  1. #1
    Hein Guest

    Deleting from database - Done so far


    Here is the code for what I have done so far


    public void removeBank(int bankNo)
    {
    try
    {

    myCon = DriverManager.getConnection(myURL,userID,password);
    stmt = myCon.createStatement();
    rs = stmt.executeQuery("Select * from Banks);

    //stmt1 = myCon.createStatement();
    rs = stmt1.executeQuery("Delete from Banks where BankNo = " + bankNo);

    myCon.close();
    }

    catch(Exception e)
    {
    System.err.println(e.toString());
    }

    }//end method


    The way I see it is that I first create a resultset containing the info I
    need. Then I delete from that resultset only the specified record, but still
    it throws me an exception stating no resultset was created.

  2. #2
    Paul Clapham Guest

    Re: Deleting from database - Done so far

    That's correct, the SQL Delete statement doesn't return a result set.
    Therefore, you need to use the executeUpdate() method, which returns an int
    (telling you how many records were deleted.)

    PC2

    Hein <heinrich@jmr.co.za> wrote in message news:3a80ffcd$1@news.devx.com...
    >
    > Here is the code for what I have done so far
    >
    >
    > public void removeBank(int bankNo)
    > {
    > try
    > {
    >
    > myCon = DriverManager.getConnection(myURL,userID,password);
    > stmt = myCon.createStatement();
    > rs = stmt.executeQuery("Select * from Banks);
    >
    > file://stmt1 = myCon.createStatement();
    > rs = stmt1.executeQuery("Delete from Banks where BankNo = " + bankNo);
    >
    > myCon.close();
    > }
    >
    > catch(Exception e)
    > {
    > System.err.println(e.toString());
    > }
    >
    > }//end method
    >
    >
    > The way I see it is that I first create a resultset containing the info I
    > need. Then I delete from that resultset only the specified record, but

    still
    > it throws me an exception stating no resultset was created.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center