VisualBuilder
  Home > Java > Tutorials > Batch Updates Using Statements - JDBC Tutorial
Tell a friend
Link to us
Total Members
      Members: 84648
     
Sitemap Forum Chat
Home
JDBC Tutorial Home
1 . Introduction To JDBC
2 . Connection Interface
3 . The Data Model For the Examples
4 . Basic CRUD functionality using Statements
5 . Handling Data with Result Sets
6 . Using PreparedStatements
7 . Scrollable and Updateable ResultSets
8 . Adding, Updating and Deleting Rows using ResultSets.
9 . Using Joins in JDBC Quries.
10 . Calling procedures with Callable Statement
11 . Transaction Management Part-1
12 . Transaction Management Part-2
13 . Connection pooling And Data Sources
14 . Batch Updates Using Statements
15 . Handling Batch/SQL Errors and Warnings
16 . Handling Blob and CLOB data using JDBC
17 . Basics for Rowsets and JdbcRowSet Example
18 . CachedRowSet
19 . JoinRowSet
20 . FilterRowSet
21 . WebRowSet
22 . Next steps
 
Java Group Home
Java Discussion (273)
Java Members (27593)
Java Resources
Java Source Code (1095)
Java Articles (5)
Java Blogs
Java Jobs
Java Components (84)
Java Books
Java Websites (126)
Java News (103)
Java Q & A (114)
- Java Ask Question
- Java Questions
- Java Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
LINQ
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Grails Tutorial
Hibernate Tutorial
Java 1.6 Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Service-Oriented Architecture (SOA) Tutorial For Managers
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (436 )
Source Code (3275 )
Articles (11 )
Components (1589 )
News (888 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Java jdbc Tutorial
 Batch Updates Using Statements
  << Prev: Connection pooling And Data Sources Next: Handling Batch/SQL Errors and Warnings >>

The Statement object can also be associated with more than one command at a time. These chunks of commands are known as batch of statements. Commands are added to the list with the Statement method addBatch and the method executeBatch submits stmt's list of commands to the underlying DBMS for execution. The execution of a batch may throw BatchUpdateException if something goes worng with the execution. All the statements only return the simple count and not any resultsets. In other words we can say the select statements are not allowed in batch statements. A Statement object's list of commands can be emptied by calling the method clearBatch on it. The following example will execute the batch of select statements.


package com.visualbuilder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class BatchProcessingExample {

/**
* @param args
*/

  public static void main(String[] args) {
    try {
         /** Loading the ODBC- Bridge driver*/
             Class.forName("com.mysql.jdbc.Driver");
         /** Getting Connection*/
            Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
         /**Creating Statement*/
           con.setAutoCommit(false);
           Statement stmt = con.createStatement();
           stmt.addBatch("INSERT INTO visualbuilder VALUES(11,'visual')");
           stmt.addBatch("INSERT INTO visualbuilder VALUES(12,'Builder')");
           stmt.addBatch("INSERT INTO visualbuilder VALUES(13,'RAD')");
           stmt.addBatch("INSERT INTO visualbuilder VALUES(14,'Eclipse')");
           stmt.addBatch("INSERT INTO visualbuilder VALUES(15,'NetBeans')");
           int [] updateCounts= stmt.executeBatch();
           con.commit();
          con.setAutoCommit(true);
         System.out.println("Batch Successful");
          con.close();
      } catch (Exception e) {
          e.printStackTrace();
       }
    }
}  


Output:-


Batch Successful


Note :- JDBC drivers are not required to support batch updates, so a particular driver might not implement the methods addBatch, clearBatch, and executeBatch. Normally a programmer knows whether a driver that he/she is working with supports batch updates, but if an application wants to check, it can call the DatabaseMetaData method supportsBatchUpdates to find out.


  << Prev: Connection pooling And Data Sources Next: Handling Batch/SQL Errors and Warnings >>
Java Jdbc Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
conference call review
VoIP Internettelefonie AT
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising