O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required