What to use: executeUpdate() or execute()?
Solution 1
The return value differs. ExecuteUpdate() returns the number of rows updated, which can be useful when running an update statement. In your case it is not needed, since you know how many records you are inserting. You can use either one.
Solution 2
In principle only the return value is different. However, I found that using jConnect 3 to access Sybase ASE 15.7, the execute() function does not block until triggers have run and closing the PreparedStatement straight away will ROLL BACK the update. (Inserting a 1s sleep makes it work for one query I tried.) By contrast, executeUpdate() does not suffer from this problem; it appears to do the right thing, and does not require an arbitrary sleep before closing the PreparedStatement.
Related videos on Youtube
neeraj narang
Updated on June 04, 2022Comments
-
neeraj narang almost 2 years
Please tell me which out of the two methods, executeUpdate and execute is the best one for an insert query like
insert into users(name, addr, city, sex, dob) values(?,?,?,?,?);
Both the statements would execute the query but which one should be ideally used for an insert query? -
neeraj narang over 12 yearsSo there are no advantages as such in using either one of them right? In this case it doesn't matter which method is used right?
-
Anthony Grist over 12 yearsFrom a readability standpoint, I think
executeUpdate()
makes it clearer that there will be changes to the data as a result of the statement being executed.