Call a local BATCH Job or Run MS ISQL

Posted on 1998-07-27
Last Modified: 2008-02-26
I would like java to 'call' or 'run' a command on the same server as java is running.  The command must run an ISQL script to work on a local SQL Server and/or batch file.  How can I do it?
Question by:snydero
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Accepted Solution

dryang earned 100 total points
ID: 1228389
Thread it! spawn a thread to run the script using the exec command. but watch out for synchronization mistakes. any comments please post again

Author Comment

ID: 1228390
I was hoping for an example of a line of code.

Expert Comment

ID: 1228391
here goes.....

1) create a thread, either by extending class 'Thread' or implementing 'Runnable' in your self created class. If you want to extend 'Thread' make sure you have 'public void run()' as part of your code. The JVM will run this method automatically after the class has been called

public class myclass extends Thread
    myclass()    //constructor

    public void run()  //you MUST have this method (overrides run method of Thread)
    {  //does something useful

In your calling program...

myclass mc = new myclass();;

and the thread runs. Its the same for implementing 'Runnable'

Check the JDK documentation for specific details and synchronization issues. (check out the key word 'synchronised')

2) After you have created your code for threading, use the 'exec' command to exececute any batch jobs or scripts.(under java.lang.Runtime)


There are various forms of exec and I reccommend that you dig around the documentation for details. Its not easy to decide which form is the best and you should take some time to look over your design specs.

note: In UNIX we use a similar method called 'fork and exec' where a seperate process is created (forked) and a command run (exec). This is where JAVA takes the idea from.

post any futhur questions ok?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1228392
Here is my code...
class HelloWorld
{      public static void main(String args[])
      {      System.out.println("Hello World!");
            rclass rc = new rclass();

class rclass extends Thread
{      rclass()
      public void run()
      {      System.out.println("In run now");

The error I get is... Can't make static reference to method java.lang.Process exec(java.lang.String) in class java.lang.Runtime.
1 error


Expert Comment

ID: 1228393
hi Syndero

Oops, Syntax error on my part.

should instantiate the Runtime object first...

Runtime rt = new Runtime();

Author Comment

ID: 1228394
I've tried every way to get your code example to work.  It DOESN'T!
Can you provide a complete listing please.
Again, I wish to run a batch file (jtest.bat) from a java program.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delete Android all or certain applications data programmatically 9 111
login form jsp example 2 50
Setup GlassFish 4 35
Java class and jar 3 42
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question