Class CopyManager


  • public class CopyManager
    extends Object
    API for PostgreSQL COPY bulk data transfer.
    • Method Detail

      • copyOut

        public long copyOut​(String sql,
                            Writer to)
                     throws SQLException,
                            IOException
        Pass results of a COPY TO STDOUT query from database into a Writer.
        Parameters:
        sql - COPY TO STDOUT statement
        to - the Writer to write the results to (row by row). The Writer is not closed at the end of the Copy Out operation.
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage errors
        IOException - upon writer or database connection failure
      • copyOut

        public long copyOut​(String sql,
                            OutputStream to)
                     throws SQLException,
                            IOException
        Pass results of a COPY TO STDOUT query from database into an OutputStream.
        Parameters:
        sql - COPY TO STDOUT statement
        to - the stream to write the results to (row by row) The stream is not closed at the end of the operation. This is intentional so the caller can continue to write to the output stream
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage errors
        IOException - upon output stream or database connection failure
      • copyIn

        public long copyIn​(String sql,
                           Reader from)
                    throws SQLException,
                           IOException
        Use COPY FROM STDIN for very fast copying from a Reader into a database table.
        Parameters:
        sql - COPY FROM STDIN statement
        from - a CSV file or such
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage issues
        IOException - upon reader or database connection failure
      • copyIn

        public long copyIn​(String sql,
                           Reader from,
                           int bufferSize)
                    throws SQLException,
                           IOException
        Use COPY FROM STDIN for very fast copying from a Reader into a database table.
        Parameters:
        sql - COPY FROM STDIN statement
        from - a CSV file or such
        bufferSize - number of characters to buffer and push over network to server at once
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage issues
        IOException - upon reader or database connection failure
      • copyIn

        public long copyIn​(String sql,
                           InputStream from)
                    throws SQLException,
                           IOException
        Use COPY FROM STDIN for very fast copying from an InputStream into a database table.
        Parameters:
        sql - COPY FROM STDIN statement
        from - a CSV file or such
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage issues
        IOException - upon input stream or database connection failure
      • copyIn

        public long copyIn​(String sql,
                           InputStream from,
                           int bufferSize)
                    throws SQLException,
                           IOException
        Use COPY FROM STDIN for very fast copying from an InputStream into a database table.
        Parameters:
        sql - COPY FROM STDIN statement
        from - a CSV file or such
        bufferSize - number of bytes to buffer and push over network to server at once
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage issues
        IOException - upon input stream or database connection failure
      • copyIn

        public long copyIn​(String sql,
                           ByteStreamWriter from)
                    throws SQLException,
                           IOException
        Use COPY FROM STDIN for very fast copying from an ByteStreamWriter into a database table.
        Parameters:
        sql - COPY FROM STDIN statement
        from - the source of bytes, e.g. a ByteBufferByteStreamWriter
        Returns:
        number of rows updated for server 8.2 or newer; -1 for older
        Throws:
        SQLException - on database usage issues
        IOException - upon input stream or database connection failure