0

i have an sql file of the following form:

CREATE VIEW dbo.SomeView
AS select * from SomeTable
GO

ALTER TABLE [SomeTable] ADD CONSTRAINT [...] PRIMARY KEY CLUSTERED ([..],[TIME_STAMP],[..])
GO

and so on.. it contains only update queries.
i want to run it on an sql server that is situated on a remote machine. I'm using java and i read it is not possible to execute a file through jdbc.
i read this related post:
How to execute sql-script file in java?

my question is, how can i execute that file if the server is on a remote machine and not on my machine (i don't have mssql server installed on my machine)?

P.S it would be nice to know if there is a solution to this problem in other languages (just a reference will do)

EDIT: the file is on the local machine.

thank ppl!

Community
  • 1
  • 1
Asher Saban
  • 4,673
  • 13
  • 47
  • 60
  • You have the sql file on your local machine and the sql server is remote or does is the server and the file on the same machine? – Eggi Mar 08 '12 at 09:40
  • the file is on my machine. the server is remote – Asher Saban Mar 08 '12 at 10:25
  • check this [page](http://lukewalsh.co.uk/blog/2008/07/connection-to-with-jdbc-to-microsoft.html) – Rakesh Mar 08 '12 at 10:27
  • This answer to the linked question is best http://stackoverflow.com/a/2071724/116509. JDBC can run the individual queries remotely once you split up the file. – artbristol Mar 08 '12 at 11:13

1 Answers1

1

Do you have developer access to the remote machine? I.e., can you open ports? You can use a simple socket and a remote shell to execute the queries (both sides can be Java but anything else will do).

If you have no administrative privileges, you might use some SSH API to login and execute a script.

If you have installed the SQL tools on your machine, you can still run them on the remote (if it is enabled and there are no firewall restrictions, for instance, but some additional configuration might be necessary). With MySQL, you may use something like this:

 mysql -u dbuser –h remote.host.name –p < script.sql

You can even do this from Java with the script you linked.

rlegendi
  • 10,466
  • 3
  • 38
  • 50