Can we use the one instance of Statment to execute more
than one query ?

Answer Posted / sachin

To make batch updates using a single statement with several
sets of input parameters, follow these basic steps:

Disable AutoCommit for the Connection object.
Invoke the prepareStatement method to create a
PreparedStatement object for the SQL statement with input
parameters.
For each set of input parameter values:
Execute setXXX methods to assign values to the input
parameters.
Invoke the addBatch method to add the set of input
parameters to the batch.
Invoke the executeBatch method to execute the statements
with all sets of parameters.
Check for errors. If no errors occurred:
Get the number of rows that were updated by each execution
of the SQL statement from the array that the executeBatch
invocation returns.
Invoke the commit method to commit the changes.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the JDBC?

547


What is meant by jdbc?

515


How can we set null value in jdbc preparedstatement?

514


What is the difference between jdbc and jndi?

479


What is executeupdate in java?

464






What is jdbc template?

509


What is JDBC Savepoint? How to use it?

679


password, is stored in as plain text. What can I do to protect my passwords?

507


Where is mysql jdbc driver located?

504


Why do we use jdbc?

504


DB2 Universal claims to support JDBC 2.0, But I can only get JDBC 1.0 functionality. What can I do?

575


What is metadata in programming?

515


There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?

604


What is the execute method in java?

539


How do I load a database driver with JDBC 4.0 / Java 6?

545