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.
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.