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
What should be done for auto generating primary key id in a table ?
What is the use of statement in jdbc?
How to insert an image or raw data into database?
Name different methods for getting streams.
Where can I find ojdbc14 jar file?
How do I load a database driver with JDBC 4.0 / Java 6?
What is represented by the connection object?
List some new features available in jdbc 4.0?
Which interface is responsible for transaction management in jdbc?
What are the basic exceptions in jdbc?
What is dburl?
How the JDBC application works?
What are the new features added to JDBC 4.0?
Is jdbctemplate thread safe?
Which database is used with java?