Statement Batch Update : Statement « Database « Java Tutorial






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!");
  }
}








20.5.Statement
20.5.1.Change the fetch size on the result set
20.5.2.Get the fetch size of a statement
20.5.3.Set the fetch size on the statement
20.5.4.Retrieving All Rows from a Database Table
20.5.5.Getting Column Names from a database table in Java
20.5.6.Retrieve a rowcount from a ResultSet
20.5.7.Setting the Number of Rows to Prefetch When Executing a SQL Query
20.5.8.Create a result set
20.5.9.Creating a Database Table called my_table with one column, col_string, which holds strings.
20.5.10.Deleting a Database Table called my_table from a database.
20.5.11.Inserting a Row into a Database Table
20.5.12.Inserting a Row into a Database Table Using a Prepared Statement
20.5.13.Deleting a Row from a Database Table
20.5.14.Statement Batch Update