-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: retrieving result-code and output -- howto? #2487
Comments
Hi sdonvanuk, I would proceed with your option #1 to get the return code as you have currently identified in your code example. The stdout is a little more problematic as JDBC does not recognize stdout. stdout is an OS feature and so the best way to capture that data is to modify your T-SQL to use the Windows command prompt redirection operator (i.e. ">") to redirect to a file. Once the CallableStatement completes, the OS should have completed writing stdout to a file which you can read into your application like any other file:
It should be noted that ROBOCOPY has it's own logging to file feature that you can use in addition to stdout or to complement the stdout log file. You can find details here:
Please let us know if this helps. Thx, |
Hi @sdonovanuk, Please let us know if you have any further questions. If not, we will move forward with closing this issue. |
Greetings. Sorry for the slow response. I was a little confused by the comment "as JDBC does not recognize stdout". Again, if I use I should add: I'm 100% aware <cough, cough> that we shouldn't be using Thank you! |
According to the docs for xp_cmdshell the data directed to stdout is returned in the stored proc result set (https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-cmdshell-transact-sql?view=sql-server-ver16#arguments). In the example code you provided you did not attempt to read the callable statement result set. Please give this a try. We will be closing this question now. |
Greetings. Please consider the following T/SQL:
That call actually has two pieces of output: (i) the result-code from
robocopy
, and (ii) output -- which is thestdout
from the call, returned as 1x column.Question/Problem: I cannot find JDBC calls (or Spring's
JdbcTemplate
) that allow me to extract both pieces of data.You can either (i) use a
CallableStatement
:. . . . to get the return-code (and any output parameter(s)), or, (ii) you can issue a regular query (e.g.
jdbcTemplate.queryForList(..)
) to get thestdout
.I cannot find a way of retrieve both sets of data. It's possible I haven't looked hard enough, or it's also possible the JDBC spec doesn't deal with this case. I'm not sure what the correct answer would be: multiple result-sets?
Any ideas? Thank you!
The text was updated successfully, but these errors were encountered: