• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in getting the number of rows updated with the UPDATE statement

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the statement.executeUpdate(String sql). The sql is a simple update statement such as UPDATE t_test set test_col='xx' where test_col='yy'
The problem is there are trigger(s) on the above table. When I execute the above query in a SQL Query analyzer the output will look like :

0 row(s) affected
0 row(s) affected
0 row(s) affected
1 row(s) affected;

Actually there is one row which was updated by the above update statement. The first three lines ( 0 rows affected ) is because of a trigger.

Now when I execute the above query I am expecting the :

int nbrRowsUpdated = stmt.executeUpdate(sql); In this case
the nbrRowsUpdated = 0. why? It should return zero only when there are no matches.

How can I overcome this problem?


Thanks!
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you mean you are gettin only the first result,means 0 rows affected. last three you are not gettin in your java code but in sql client you are gettin all four. right?

interesting. dont know why.
 
srinivas daroori
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's right! How do I know that my row has been updated. In this case can't I use the int returned by stmt.executeUpdate() ?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to do this update using executeQuery(). it sounds like a wrong way, but just try it out. and check the result in result set.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic