Inserting Records in Batch Using JDBC
It is carried out using the functions namely addBatch() and executeBatch() methods. For that lets us do have a prior understanding of JDBC drivers. So, in order to connect to your database in Java, you need a JDBC driver. Every database (MySQL, Oracle, etc.) comes with its own JDBC driver, usually built by the database vendor and found on the database’s website. Considering the example of the MySQL database, you will need to go to the MySQL website, download the MySQL JDBC driver .jar file (also called Connector/J), and add it to your project.
Method 1: addBatch()
This method adds the parameter values to the batch internally. You can now add another set of values, to be inserted into the SQL statement. Each set of parameters are inserted into the SQL and executed separately, once the full batch is sent to the database.
Method 2: executeBatch()
This method is called, which executes all the batch updates. The SQL statement plus the parameter sets are sent to the database in one go. The int array returned by the executeBatch() method is an array of int telling how many records were affected by each executed SQL statement in the batch.
Syntax: Creation of the database
create table emp(eid varchar(200) unique,ename varchar(200)
|. . .||. . .|