In Postgres, large objects
(also known as blobs) are used to hold
data in the database that cannot be stored in a normal SQL table.
They are stored as a Table/Index pair, and are referred to from
your own tables by an OID value.

Important: For Postgres, you must access large objects
within an SQL transaction. Although this has always been true in
principle, it was not strictly enforced until the release of
v6.5. You would open a transaction by using the setAutoCommit() method with an input parameter of
false:

Connection mycon;
...
mycon.setAutoCommit(false);
... now use Large Objects

Now, there are two methods of using Large Objects. The first is
the standard JDBC way, and is
documented here. The other, uses our own extension to the api,
which presents the libpq large object API to Java, providing even better access to large
objects than the standard. Internally, the driver uses the
extension to provide large object support.

In JDBC, the standard way to access
them is using the getBinaryStream() method in ResultSet, and
setBinaryStream() method in PreparedStatement. These methods make
the large object appear as a Java stream, allowing you to use the
java.io package, and others, to manipulate the object.

For example, suppose you have a table containing the file name
of an image, and a large object containing that image:

Now here you can see where the Large Object is retrieved as an
InputStream. You'll also notice that we close the stream before
processing the next row in the result. This is part of the
JDBC Specification, which states that
any InputStream returned is closed when ResultSet.next() or
ResultSet.close() is called.

Submit correction

If you see anything in the documentation that is not correct, does not match
your experience with the particular feature or requires further clarification,
please use
this form
to report a documentation issue.