The JDBC api provides methods to exceute some number of SQL queries in single batch.

The example below performs 3-4 INSERT queries in a single batch.

 import java.sql.*;

public class testBatch 
{
    public static void main(String[] args) 
    {
        DB db = new DB();
        Connection conn=db.dbConnect(
    "jdbc:jtds:sqlserver://localhost:1433/tempdb","sa","");
        db.performBatch(conn);
    }
}

class DB
{
    public DB() {}

    public Connection dbConnect(String db_connect_string, 
  String db_userid, String db_password)
    {
        try
        {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            Connection conn = DriverManager.getConnection(
    db_connect_string, db_userid,db_password);
            System.out.println("connected");
            return conn;
            
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return null;
        }
    }

    public void performBatch(Connection conn)
    {
        String query;
        Statement stmt;
        
        try
        {
            conn.setAutoCommit(false);

            stmt = conn.createStatement();  

            stmt.addBatch("INSERT INTO customer " + 
                 "VALUES('name2', 'temp2',27)");
            stmt.addBatch("INSERT INTO customer " +
                "VALUES('name3', 'temp3',28)");
            stmt.addBatch("INSERT INTO customer " +
                "VALUES('name4','temp4',29)");
        
            int [] updateCounts = stmt.executeBatch();
            conn.commit();
            conn.setAutoCommit(true);
            stmt.close();
            conn.close();

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

};