0

I have a large number of source commands to execute. So I want to write some Java code to do this. Is there a way to do this in Java?

source command is like this:

 mysql> source /home/liova/download/tpch/queries/Q1.sql;
4
  • Not able to understand. What type of source command you cant to say ? Commented May 9, 2012 at 4:53
  • @BhavikAmbani, thanks for bringing this out. I've added some details. Commented May 9, 2012 at 4:55
  • I think you should find this post interesting:[Stack Overflow Run SQL Script with MySQL][1] [1]: stackoverflow.com/questions/1044194/… Commented May 9, 2012 at 4:57
  • Then I think Runtime.exec() will work for you Commented May 9, 2012 at 4:59

2 Answers 2

1

You can execute any shell command using Runtime.exec:

Runtime.exec("mysql db_name < /home/liova/download/tpch/queries/Q1.sql");
Sign up to request clarification or add additional context in comments.

3 Comments

By the way, can I record the time needed for this query?
Sure, using plain old System.currentTimeMillis() before and after.
You can make it block using waitFor(). Just be aware of the pitfalls: javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
0

You can use Runtime class to execute any commands in java. It executes the command as seperate process.

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.