How to do it...

Each database has its specific way of storing a LOB. In the case of PostgreSQL, Blob is usually mapped to the OID or BYTEA data type, while Clob and NClob are mapped to the TEXT type. To demonstrate how to do this, let's create tables that can store each of the large object types. We will write a new method that creates tables programmatically:

void execute(String sql){  try (Connection conn = getDbConnection()) {    try (PreparedStatement st = conn.prepareStatement(sql)) {      st.execute();    }  } catch (Exception ex) {    ex.printStackTrace();  }}

Now, we can create three tables:

execute("create table images (id integer, image bytea)");execute("create table lobs (id integer, lob oid)");execute("create table texts (id integer, text text)" ...

Get Java 11 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.