0

I've tried using Base.exec / new DB("default").exec("refresh materialized view concurrently ... and neither work. No errors, but the statement isn't run.

dessalines
  • 6,352
  • 5
  • 42
  • 59

1 Answers1

0

Finally figured this out. Not sure why, but Base.exec won't work, only Statement.executeUpdate.

// Open your connection
String sql = "refresh materialized view concurrently MY_VIEW";
try {
    Connection conn = new DB("default").connection();
    Statement stmt = conn.createStatement();
    stmt.executeUpdate(sql);
    conn.commit();
    stmt.close();
} catch (SQLException e) {
    e.printStackTrace();
}
dessalines
  • 6,352
  • 5
  • 42
  • 59
  • 1
    it might be related to the fact that `Base.exec()` uses `PreparedStatement` and you are using just a `Statement`. Might be some other idiosyncrasy with the driver – ipolevoy Jun 15 '17 at 20:20
  • 1
    Also, you can replace `Connection conn = new DB("default").connection();` with `Connection conn = Base.connection();`, see more at: http://javalite.io/database_connection_management#db-and-base-classes – ipolevoy Jun 15 '17 at 20:21