tags:

views:

83

answers:

3

By seeing the ResultSet.getWarnings() method there must be some way to pass warning/info messages from stored procedures to Java layer but found most of the drivers doesn't implement this method. Are there any way to send info/warning message from stored procedure to Java layer?

A: 

Did you already try using CallableStatement when calling stored procedures. I think that's how it should be done. Maybe there getWarnings() is supported.

CallableStatement cs = Connection.prepareCall(..)
cs.registerOutParameter(..)
cs.setXXX
....
cs.executeUpdate()
cs.getXXX()
cs.getWarnings()
jitter
+1  A: 

This is going to depend on the specific server. In MSSQL, you would use RAISERROR. I think the behavior of just hiding in the get warnings or throwing an SQLException (which you can always catch and parse the message of) will depend on the level.

But the if and how it is supported will vary by database vendor, so you should target your question to the specific database you are interested in.

Yishai
A: 

I presume by warning/info messages you mean text strings generated by the stored procedure itself. I would recommend adding an out parameter to the stored procedure and use that to return messages/warnings. If your stored procedures are written in Java on Oracle you could even serialize the list of messages, return it across the JDBC interface as a blob, and reconstitute it in the client Java code. I did this in a large system several years ago and it worked quite well.

Jim Garrison
We have lots of stored procedure already written which are difficult to change now. Apart from out parameter registration are there any other way to pass message from Oracle stored procedure to Java layer?
Venkat
How are the warnings/info messages currently being generated by the stored procedures?
Jim Garrison
Currently we use raise_error with some SQL code to differentiate between error and warning. But this doesn't work well in all cases hence I am looking for an alternative approach.
Venkat