O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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. So let's write a new method that will allow us to create tables programmatically:

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

This differs from executeUpdate(), as it calls the execute() method of PreparedStatement instead of executeUpdate(). In principle, we can use execute() instead of executeUpdate() everywhere, but in our implementation of executeUpdate(), we expect a return value ...

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