Two Laptop Bag*
The moose likes JDBC and the fly likes To delete a record  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "To delete a record  " Watch "To delete a record  " New topic
Author

To delete a record

Rajesh Pathak
Ranch Hand

Joined: Aug 15, 2002
Posts: 56
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?


Rajesh(Bangalore,India)<br />SCJP2, SCWCD, SCEA, IBM-XML, UML-OOAD, IBM-Enterprise Connectivity with J2EE.
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
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

Joined: Aug 15, 2002
Posts: 56
Thanks a lot Kevin for a explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To delete a record
 
Similar Threads
NX: URLyBird Database Record Number Question
Audio in Java
Why not use an ArrayList for caching instead of HashMap?
NX: URLyBird1.1.3, about the find method in Data class.
URLyBird GUI MVC <-> Business Layer in a Thin Client and HashMap vs. ArrayList