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!

4
  • 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? Commented Mar 8, 2012 at 9:40
  • the file is on my machine. the server is remote Commented Mar 8, 2012 at 10:25
  • check this page Commented Mar 8, 2012 at 10:27
  • This answer to the linked question is best stackoverflow.com/a/2071724/116509. JDBC can run the individual queries remotely once you split up the file. Commented Mar 8, 2012 at 11:13

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.