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)
eid ename 181FA04001 181FA04001 181FA04002 181FA04002 . . . . . . 181FA04500 181FA04500
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.