2

In my Java program, I am trying to execute a bunch of SQL scripts using sqlcmd via getRuntime.exec().

Earlier, I had been using osql this way -

osql -n -S SERVER -U sa -P PASSWORD -q "SET NOCOUNT ON" -i "INPUTSCRIPT.sql"

However, in the case of sqlcmd, the -i and -q switches are mutually exclusive. How do I do this in sqlcmd?

Note:

  1. I'd rather not modify the SQL scripts to include SET NOCOUNT ON in each file.

  2. There's already been a very similar question here. That solution discusses setting environment variables. Is that possible using Java?

Community
  • 1
  • 1
GPX
  • 3,506
  • 10
  • 52
  • 69

1 Answers1

6

You can specify multiple scripts for the i switch so you can do this:

sqlcmd ... -i SetNoCountOn.sql,MyScript1.sql,MyScript2.sql

That is, create a an extra script that just has SET NOCOUNT ON

gbn
  • 422,506
  • 82
  • 585
  • 676
  • This works like a charm. But when I execute thousands of scripts, there is quite a noticeable (but not much) hit on the process time. Is there any way to improve on that? – GPX Oct 01 '11 at 02:39