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

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, ...

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