views:

169

answers:

1

I have found the following links for executing script using java i.e. http://stackoverflow.com/questions/2071682/how-to-execute-sql-script-file-in-java . But it is specific to postgre and mysql.

I am looking for same solution for executing script in Sql server 2005. I am not acquinted with SQL Command Line. I have to make a batch containing series of calling different method of a class which also include the executing the script in the middle of batch. I googled it. But, i am not able to find the solution for my problem. Thanks in advance.

+1  A: 

Instead of a dirty solution like stored procedures, why don't you try the one found in 2071682? Instead of the psql command, try Sqlcmd -Shostname\dbname -U username -p password -i sqlscriptfile. This should connect to the database, using SQL Server authentication, and run the script you specify. Pablo's answer in the referenced question should do the rest. Depending on your path, you might need to alter the 'Sqlcmd' bit to reflect the location of the program on your machine.

To learn more about the command line utility, check out this article on databasejournal.com.

Matt Luongo