Reading:  

Getting started with JDBC


Batch Processing

Batch Processing allows group related SQL statements into batch and submit them with one call to database. Sending Several SQL into database will improve performance and communication overhead.

Batching with Statement Object:

Batch processing typical sequence of steps to use Statment Object:

  • Create a Statement object methods.
  • Add many SQL statements into batch using addBatch()
  • Execute all SQL statements using executeBatch()
  • Commit all changes.

Example:

The following code snippet Statement object:

// statement Create object
Statement stmtmnt = conn1.createStatement();
//Set auto-commit false
Conn1.setAutoCommit(false);
// SQL Create
String SQL = "INSERT INTO USER (user_id, user_first,user_last,user_age) " +
"VALUES(200,'Zen', 'L', 31)";
// SQL statement in batch.
stmtmnt.addBatch(SQL);
// add SQL statement
String SQL = "INSERT INTO USER (user_id,user_first,user_last,user_age) " +
"VALUES(201,'Ranch', 'K', 35)";
// Add above SQL statement in the batch.
stmtmnt.addBatch(SQL);

// Create an int[] to hold returned values
int[] count = stmtmnt.executeBatch();
//Explicitly commit statements to apply changes
Conn1.commit();

Description

This tutorial is focused on getting you started with JDBC 4.1. This tutorial has following parts

  1. Introduction
  2. SQL Syntax
  3. Setting up Environment
  4. Getting started with some samples
  5. Connecting to database
  6. Statements
  7. Result Sets
  8. Data Types
  9. Transactions
  10. Exception handling
  11. Batch Processing
  12. Streaming Data
  13. More JDBC Examples

Leave your feedback to help us improve next time. Also let us know if you see any errors that needs to be corrected



Prerequisites

Understanding of Java language a must to understand various things in this tutorial

Audience

Absolute beginners who wants to get started with JDBC

Author: Subject Coach
Added on: 8th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!