How to do it...

As in the previous recipe, we will continue using the PostgreSQL database for demonstration purposes. Before writing custom SQL statements, functions, and stored procedures, you should look at the list of already existing functions first. Usually, they provide a wealth of functionality.

Here is an example of calling the replace(string text, from text, to text) function that searches the first parameter (string text) and replaces it with all the substrings that match the second parameter (from text ) with the substring provided by the third parameter (string text):

String sql = "{ ? = call replace(?, ?, ? ) }";try (CallableStatement st = conn.prepareCall(sql)) {  st.registerOutParameter(1, Types.VARCHAR);  st.setString(2, "Hello, ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.