Re: How do I capture the message from user defined function - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: How do I capture the message from user defined function
Date
Msg-id 3E3E1A8D.3A817262@ejurka.com
Whole thread Raw
In response to Re: How do I capture the message from user defined function  ("etsuko shimabukuro" <etsukos@meta-bit.com>)
Responses Re: How do I capture the message from user defined function  ("etsuko shimabukuro" <etsukos@meta-bit.com>)
List pgsql-jdbc
etsuko shimabukuro wrote:
>
> Dear Kris,
>
> Thank you for your email.
> I tried this getWarnings(), but it didn't capture the "notice" level of the
> messages.
>
> Regards,
> Etsuko
>


The following code works for me on both 7.2.3 and 7.3.1 servers with the
latest jdbc driver.  If you are running on the 7.3 series you should
also check the value of client_min_messages in postgresql.conf is set to
an appropriate value for you to receive notice messages.

Kris Jurka

import java.sql.*;

public class Raise {

    public static void main(String args[]) throws Exception {
        Class.forName("org.postgresql.Driver");
        Connection conn =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka","");
        Statement stmt = conn.createStatement();
        stmt.executeUpdate("CREATE OR REPLACE function myraise() returns int
as 'BEGIN RAISE NOTICE ''Hello''; RETURN 0; END' LANGUAGE 'PLPGSQL'");
        ResultSet rs = stmt.executeQuery("SELECT myraise()");
        SQLWarning warning = conn.getWarnings();
        System.out.println(warning);
    }
}

pgsql-jdbc by date:

Previous
From: "etsuko shimabukuro"
Date:
Subject: Re: How do I capture the message from user defined function
Next
From: "etsuko shimabukuro"
Date:
Subject: Re: How do I capture the message from user defined function