Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Count number of deleted rows

 
Rupjit Chakraborty
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
 
Stefan Evans
Bartender
Posts: 1807
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic