JDBC Batch Insert is a set of SQL Statements sent to the database and executed as a single unit. The Statement object performs the batch update.
Understand with Example
The Tutorial depicts you an example from JDBC Batch Insert, An empty array object is linked, whenever a statement object is created. The multiple SQL statements is added to the empty array. This statements is executed as a batch. The con.setAutoCommit( ) is used to disable the auto commit.The batch contain three SQL INSERT statement added to a batch using the addBatch ( ).The code show you the list of method required to carry out JDBC Batch Insert are as follows -
Driver loading - Once the sql package is imported, the second step is the loading of a driver class that call a forclass.name with driver name passed as argument. Once your driver is loaded you connect your front end java application to the backend database. If there is an exception in try block, the catch block subsequently handle the exception.
DriverManager.getconnection ( ) : This is used to establish a connection between database and respective url.
. con.createStatement ( ) : This is used to provide you a Sql object. On establishing a connection ,your application can interact with backend database. An connection object is used to send and execute Sql statement to a backend database.
st.addbatch( ) : This method is used to add the sql parameter to the batch of command.
executeQuery ( ) : This method is used to return the value obtained from select command and is stored in result set object.rs.next( ) - This method is used to retrieve the element from a database in successively sequence.
The print ln print the element from rs.getString ( ),which return you the value of elements from the database.
No Name 4 Komal 5 Ajay 6 Santosh
Posted on: November 17, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles