Statement Batch Update : Batch Update « Database SQL JDBC « Java






Statement Batch Update

  

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class Main {
  public static void main(String[] argv) throws Exception {

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial",
        "root", "root");

    con.setAutoCommit(false);
    String table1 = "INSERT emp_sal VALUES('v',1200)";
    String table2 = "DELETE FROM movies WHERE title = 'r'";
    Statement st = con.createStatement();
    st.addBatch(table1);
    st.addBatch(table2);
    int count[] = st.executeBatch();
    con.commit();
    con.close();
    System.out.println("Successfully!");
  }
}

   
    
  








Related examples in the same category

1.Create a batch update in JDBC
2.Batch Update Insert
3.Batch update: add Batch commands
4.Check Batch Update Result
5.Batch Update Demo
6.Batch update for MySQL
7.Deal with batch update exception and results
8.Demo Prepared Statement Add Batch MySQL
9.Determining If a Database Supports Batching
10.Prepared Statement With Batch Update