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

As in the previous recipe, we will continue using the PostgreSQL database for demonstration purposes. Before writing custom SQL statements, functions, and stored procedures, one 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 finds all the from text  substrings in string text and replaces them with to text:

String sql = "{ ? = call replace(?, ?, ? ) }";try (CallableStatement st = conn.prepareCall(sql)) {  st.registerOutParameter(1, Types.VARCHAR);  st.setString(2, "Hello, World! Hello!");  st.setString(3, "llo");  st.setString(4, "y");  st.execute();  String res = st.getString(1

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