This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
srinivas daroori
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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!
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic