Class Batch

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, Configurable<Batch>

    public class Batch
    extends BaseStatement<Batch>
    Represents a group of non-prepared statements to be sent to the RDMBS in one "request".
    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • parts

        private final java.util.List<java.lang.String> parts
    • Constructor Detail

      • Batch

        public Batch​(Handle handle)
    • Method Detail

      • add

        public Batch add​(java.lang.String sql)
        Add a statement to the batch
        Parameters:
        sql - SQL to be added to the batch, possibly a named statement
        Returns:
        the same Batch statement
      • execute

        public int[] execute()
        Execute the batch and return the number of rows affected for each batch part. Note that some database drivers might return special values like Statement.SUCCESS_NO_INFO or Statement.EXECUTE_FAILED.
        Returns:
        the number of rows affected per batch part
        See Also:
        Statement.executeBatch()
      • createStatement

        java.sql.Statement createStatement()
                                    throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • cleanupStatement

        void cleanupStatement​(java.sql.Statement statement)
                       throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • mungeBatchException

        static java.sql.SQLException mungeBatchException​(java.sql.SQLException e)
        SQLExceptions thrown from batch executions have errors in a SQLException.getNextException() chain, which doesn't print out when you log them. Convert them to be Throwable.addSuppressed(Throwable) exceptions, which do print out with common logging frameworks.
        Parameters:
        e - the exception
        Returns:
        the 'suppressed' munged exception change