Reputation: 480
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?
Upvotes: 9
Views: 14841
Reputation: 399
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.
Upvotes: 2
Reputation: 75619
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.
Upvotes: 16