This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Originally posted by Rajesh Pathak: I want to write a JDBC code which will remove a record from the database. Which method should I use should I use executeUpdate or execute? Does any of them should have advantage over other?
Use executeUpdate(). While execute() will work, it is meant for situations where you do not know whether the SQL will return a ResultSet or a count of rows affected or possible both. This might happen if you let a user enter arbitrary SQL, or when you are calling a function that returns both result sets and a count of affected rows. So, the advantage that execute() has over executeUpdate() is that you can use it in any situation. The disadvantage is that if you don't know the return value, you have to call extra methods to determine whether you have a ResultSet or a count. Thus, it's a little more straightforward to use executeQuery() when you know that you will get a ResultSet from an SQL statement, and executeUpdate() when you know the SQL will return a count. K Mukhar http://home.earthlink.net/~kmukhar