aspose file tools*
The moose likes JDBC and the fly likes problem in getting the number of rows updated with the UPDATE statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in getting the number of rows updated with the UPDATE statement" Watch "problem in getting the number of rows updated with the UPDATE statement" New topic
Author

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

srinivas daroori
Greenhorn

Joined: Feb 23, 2004
Posts: 18
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Feb 23, 2004
Posts: 18
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

Joined: Aug 15, 2004
Posts: 2874
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in getting the number of rows updated with the UPDATE statement