[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1361
  • Last Modified:

capture raise notice with java

How do I capture in java a raise notice message from a postgreSQL procedure?

Ex :
Say the following hypothetical body for an sql function :
       BEGIN
            SELECT * INTO aRecord FROM aTable WHERE NEW.attribute = attribute;
            IF NOT FOUND THEN
                  RAISE NOTICE ' Not found %', NEW.attribute;
                  RETURN NULL;
            ELSE
                  RETURN NEW;
            END IF;
      END;

And the following query attached to the above function with a trigger :
INSERT INTO anotherTable
VALUES ('attribute1', 'attribute2');

How do I capture that raise notice in java (to do a system.out.println for instance) when the query returns null because of the trigger associated to a function like the one above?
0
Emilie
Asked:
Emilie
  • 3
  • 3
2 Solutions
 
objectsCommented:
I don't believe you can sorry
0
 
Tomas Helgi JohannssonCommented:
        Hi!

Try using the SQLException in a try catch block around your code.
See the following examples
http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQLException.htm

Hope this helps.

Regards,
    Tomas Helgi
0
 
objectsCommented:
RAISE NOTICE just logs afaik, don't believe an exception gets thrown
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Tomas Helgi JohannssonCommented:
      Hi!

I belive that it could be controled through the CLIENT-MIN-MESSAGE config
 
http://www.postgresql.org/docs/8.3/interactive/plpgsql-errors-and-messages.html
http://www.postgresql.org/docs/8.3/interactive/runtime-config-logging.html#GUC-CLIENT-MIN-MESSAGES

Regards,
   Tomas Helgi
0
 
objectsCommented:
only EXCEPTION raises an error
"the other levels only generate messages of different priority levels"
0
 
Tomas Helgi JohannssonCommented:
Hmmm, yes you are right.

I confused it with the SQL Warning/Notice handling. ;)

Here is an example on how to display warnings/notices from the db in the client
http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQL-Warning.htm
http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetSqlWarningStatementobject.htm

Regards,
    Tomas Helgi
0
 
EmilieAuthor Commented:
Thank you both!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now