Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To delete a record

 
Rajesh Pathak
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kevin Mukhar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajesh Pathak
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Kevin for a explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic