Amit Bhandari
Amit Bhandari

Reputation: 551

What is the difference between executeNonQuery() and executeUpdate() in java?

I had read about executeNonQuery() and executeUpdate() methods in java. But could not understand any difference among them. It says return type of executeUpdate() is an int that indicates the number of rows affected, or 0 if using a DDL statement, and is used to Runs the given SQL statement, which can be an INSERT, UPDATE, or DELETE statement; or an SQL statement that returns nothing, such as an SQL DDL statement.

same is what I read about executeNonQuery() method.

So what is the difference between these two methods?

Upvotes: 0

Views: 4463

Answers (2)

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81694

The two methods are entirely equivalent, the only meaningful difference being that executeUpdate() is part of the Java java.sql.Statement interface, while executeNonQuery() is a .NET method in the SqlCommand class! As you might imagine, many people would consider this little detail to be of some importance.

Upvotes: 3

AllTooSir
AllTooSir

Reputation: 49372

As far as I know ,ExecuteNonQuery() is there in .NET to execute UPDATE, INSERT and DELETE queries. As per the documentation :

For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. For all other types of statements, the return value is -1.

I have never heard of such method in JAVA API.

executeQuery() is used for command objects, like fire a "select statement" to database and fetch values.

Upvotes: 2

Related Questions