Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

By "Messages" I mean the Messages tab in the following figure, which includes "Warning", "n rows affected" and in the figure below, the execution time. In JDBC, ResultSet class is used to retrieve the "Results". Is there any way to get all the information in the "Message" tab through JDBC?

enter image description here

share|improve this question

You can get most of those messages, but unfortunately not all. See my question on Stackoverflow regarding that.

In general those messages (e.g. messages from a PRINT statement) are returned as warnings on the Statement object by the JDBC driver. To retrieve them use Statement.getWarnings() in a loop:

Statement stmt = ...;

SQLWarning warning = stmt.getWarnings();

while (warning != null)
   warning = warning.getNextWarning();

I have seen some messages also being returned on the Connection instance rather than the Statement. If you don't see anything, try the above code with your Connection instance.

share|improve this answer
Thanks for your reply. I've tried but it seems only the print stmt returns a msg. I'd like to show the execution time by executing "set statistics time on" but I didn't see anything, either by stmt or Connection instance. I was wondering if you've ever seen message returned by other statements other than PRINT statement? – zli89 Jun 12 '13 at 19:16
Great find but is there any reason it would only get the first printed message? – inquisitiveIdiot Oct 14 '15 at 14:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.