• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Count number of deleted rows

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to write a small code to delete a row in database and then count the number of rows deleted(which should obviously be 1). However, I am not getting the desired output.
Please help me correct my code



Thanks in advance
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is counting the number of rows returned by the query manually in the loop.

select count(*) from a table will return you one row being the number of rows in that table.

So bfr will always be 1
aft will always be 1
And your difference will always be 0.

Suggestions: Retrieve the count using rs.getInt()

Also you might want to take a look at the method executeUpdate in the API:




 
Rupjit Chakraborty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. executeUpdate() works fine. Are there any downsides of using it?
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic