Top Description Fields Constructors Methods
org.postgresql.copy

public Class CopyManager

extends Object
Class Inheritance
Imports
org.postgresql.core.BaseConnection, .Encoding, .QueryExecutor, org.postgresql.util.ByteStreamWriter, .GT, .PSQLException, .PSQLState, java.io.IOException, .InputStream, .OutputStream, .Reader, .Writer, java.sql.SQLException

API for PostgreSQL COPY bulk data transfer.

Field Summary

Modifier and TypeField and Description
private final BaseConnection
pack-priv static final int
private final Encoding
private final QueryExecutor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CopyDual
public CopyIn
public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyIn
(final String
COPY FROM STDIN statement
sql
,
Reader
a CSV file or such
from
)

Use COPY FROM STDIN for very fast copying from a Reader into a database table.

public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyIn
(final String
COPY FROM STDIN statement
sql
,
Reader
a CSV file or such
from
,
int
number of characters to buffer and push over network to server at once
bufferSize
)

Use COPY FROM STDIN for very fast copying from a Reader into a database table.

public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyIn
(final String
COPY FROM STDIN statement
sql
,
InputStream
a CSV file or such
from
)

Use COPY FROM STDIN for very fast copying from an InputStream into a database table.

public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyIn
(final String
COPY FROM STDIN statement
sql
,
InputStream
a CSV file or such
from
,
int
number of bytes to buffer and push over network to server at once
bufferSize
)

Use COPY FROM STDIN for very fast copying from an InputStream into a database table.

public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyIn
(String
COPY FROM STDIN statement
sql
,
ByteStreamWriter
the source of bytes, e.g. a ByteBufferByteStreamWriter
from
)

Use COPY FROM STDIN for very fast copying from an ByteStreamWriter into a database table.

public CopyOut
public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyOut
(final String
COPY TO STDOUT statement
sql
,
Writer
the Writer to write the results to (row by row). The Writer is not closed at the end of the Copy Out operation.
to
)

Pass results of a COPY TO STDOUT query from database into a Writer.

public long

Returns:

number of rows updated for server 8.2 or newer; -1 for older
copyOut
(final String
COPY TO STDOUT statement
sql
,
OutputStream
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
to
)

Pass results of a COPY TO STDOUT query from database into an OutputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

connectionback to summary
private final BaseConnection connection
DEFAULT_BUFFER_SIZEback to summary
pack-priv static final int DEFAULT_BUFFER_SIZE
encodingback to summary
private final Encoding encoding
queryExecutorback to summary
private final QueryExecutor queryExecutor

Constructor Detail

CopyManagerback to summary
public CopyManager(BaseConnection connection) throws SQLException

Method Detail

copyDualback to summary
public CopyDual copyDual(String sql) throws SQLException
copyInback to summary
public CopyIn copyIn(String sql) throws SQLException
copyInback to summary
public long copyIn(final String sql, Reader from) throws SQLException, IOException

Use COPY FROM STDIN for very fast copying from a Reader into a database table.

Parameters
sql:String

COPY FROM STDIN statement

from:Reader

a CSV file or such

Returns:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage issues
IOException:
upon reader or database connection failure
copyInback to summary
public long copyIn(final 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:String

COPY FROM STDIN statement

from:Reader

a CSV file or such

bufferSize:int

number of characters to buffer and push over network to server at once

Returns:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage issues
IOException:
upon reader or database connection failure
copyInback to summary
public long copyIn(final String sql, InputStream from) throws SQLException, IOException

Use COPY FROM STDIN for very fast copying from an InputStream into a database table.

Parameters
sql:String

COPY FROM STDIN statement

from:InputStream

a CSV file or such

Returns:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage issues
IOException:
upon input stream or database connection failure
copyInback to summary
public long copyIn(final 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:String

COPY FROM STDIN statement

from:InputStream

a CSV file or such

bufferSize:int

number of bytes to buffer and push over network to server at once

Returns:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage issues
IOException:
upon input stream or database connection failure
copyInback to summary
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:String

COPY FROM STDIN statement

from:ByteStreamWriter

the source of bytes, e.g. a ByteBufferByteStreamWriter

Returns:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage issues
IOException:
upon input stream or database connection failure
copyOutback to summary
public CopyOut copyOut(String sql) throws SQLException
copyOutback to summary
public long copyOut(final String sql, Writer to) throws SQLException, IOException

Pass results of a COPY TO STDOUT query from database into a Writer.

Parameters
sql:String

COPY TO STDOUT statement

to:Writer

the Writer to write the results to (row by row). The Writer is not closed at the end of the Copy Out operation.

Returns:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage errors
IOException:
upon writer or database connection failure
copyOutback to summary
public long copyOut(final String sql, OutputStream to) throws SQLException, IOException

Pass results of a COPY TO STDOUT query from database into an OutputStream.

Parameters
sql:String

COPY TO STDOUT statement

to:OutputStream

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:long

number of rows updated for server 8.2 or newer; -1 for older

Exceptions
SQLException:
on database usage errors
IOException:
upon output stream or database connection failure