How can I get the messages sent by the server while I'm executing a stored procedure via the JDBC driver?
I need to get my own debug messages (done through the print() function)
and also standard server messages (such as "x row(s) affected" or
results from SET STATISTICS TIME ON). Is this possible?
Many thanks.
Carlos
Hi Carlos,
These messages come back as warnings. You need to call Statement.getWarnings to retrieve them. See http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#getWarnings() for usage.
Hope this helps.
--David Olix
JDBC Development
|||Hi David.That didn't work for me. I am using SQL Server 2005 JDBC driver version 1.1, and here's my calling syntax:
SQLServerConnectionPoolDataSource ds = new SQLServerConnectionPoolDataSource();
//(sic) set the datasource parameters...
Connection c = c.getPooledConnection().getConnection();
CallableStatement cs = c.prepareCall("{call myStoredProcedure(?,?)");
//(sic) set the stored procedure parameters...
ResultSet rs = cs.executeQuery();
SQLWarning w = cs.getWarnings();
while( w!=null ){
System.out.println(w.getMessage());
w=w.getNextWarning()
}
When debugging, I see that the first call to
cs.getWarnings() returns a null value. I also tryed rs.getWarnings()
and c.getWarnings(), and both returned null as well. When calling the
same stored
procedure through QueryAnalyser, all the messages are there.
Any ideas on what might be causing this?
Thx,
Carlos
|||
What you have should have worked if the warning message appeared before the result set. If the message came after the result set, however, you would need to process the rows in the result set before the messages can be extracted with cs.getWarnings. To be sure that you're getting through all of the results, including any warnings, you should call Statement.getMoreResults until there are no more results. See http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#getMoreResults() for how.
Thanks,
--David
No comments:
Post a Comment