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
How the JDBC application works?
What is jdbc odbc driver?
How to check jdbc driver version in sql server?
Result set’s index starts with 0 or 1?
Why can't I invoke the ResultSet methods afterLast and beforeFirst when the method next works?
How can we set null value in jdbc preparedstatement?
What is the benefit of having jdbcrowset implementation? Why do we need a jdbcrowset like wrapper around resultset?
Why do we need jdbc api?
What does the jdbc resultsetmetadata interface?
What is the JDBC?
What is the advantage of namedparameterjdbctemplate?
What is thin driver in jdbc?
What is meant by jdbc and odbc?
How a database driver can be loaded with jdbc 4.0 / java 6?
Can resultset be null in java?