DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Hybrid View

  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.




Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links