Share on Google+Share on Google+

Alter Database Table Using JDBC Batch Process

In this example, we are discuss about alter database table using JDBC Batch process.

Alter Database Table Using JDBC Batch Process:

In this example, we are discuss about alter database table using JDBC Batch process.

First of all, we will create a java class

 In this class we will create database connection as:

Connection connection = null;


connection = DriverManager.getConnection


Now we will used sequence of the step for Batch processing for alter database table.

1. Create Statement object using createStatement() method on the created Connection object as:

Statement stmt = connection.createStatement();

2. set auto commit is false using setAutoCommit() as:


3. Create SQL alter table statement for modify the database user table

 and add these statement in batch using addBatch() method as:

String query = "ALTER TABLE user ADD address varchar(50)";


4. Execute the SQL statements using executeBatch() method on created statement object as:


5. Last commit the connection using commit() method as:


The code of the class is:

import java.sql.*;
public class BatchAlterTable {
  public static void main(String[] args) {
        Connection connection = null;
          connection = DriverManager.getConnection(
              // Create statement object  
              Statement stmt = connection.createStatement();            
              // Set auto-commit to false
              // Alter table query
              String query1 = "ALTER TABLE user ADD address varchar(50)";            
              System.out.println("Alter table by Batch processing" );

             // connection committed
          catch (SQLException s){
            System.out.println("SQL Exception " + s);
        catch (Exception e){


Program output:

The database table output before alter is:

The eclipse console output is:

The database table output after alter is:

Download source code



Posted on: October 14, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null