Running a db2 command from Java Application ??

Hi All,
I have to write an application in JDBC that can retrieve a list of databases on a db2 server, the only way I know is the db2 command "list database directory", but I can not use it in a JAVA program, is there a solution for this?
Can anyone help me in this regard ?
Thanks in Advance.

If your driver implement it you can list databases with DatabaseMetaData
Connection conn = ...
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs = meta.getCatalogs();
while (rs.next())
    System.out.println(rs.getString("TABLE_CAT"));
}

Similar Messages

  • Can I execute MySql's command from java application?

    Can I execute MySql's command from java application? And how?
    For example :
    load data local infile 'D:\\myData.txt'
    into table myTable
    fields terminated by ';'
    lines terminated by '\n';

    1. get the jdbc driver for mysql from the mysql site at: http://dev.mysql.com/downloads/connector/j/5.0.html
    2. follow the installation instructiions... which you'll also find in your mysql manual...
    Happy travels. Keith.

  • How to execute any cmd command from java application?

    Hi all,
    How to execute or call any command of cmd from java application??
    Is there any method to do so??
    Or, is it possible to do it using Runtime.exec() ??? And if so, how to use it, please explain with ab example...
    I'll highly appreciate....
    Thank you.

    If google would be the best option, then I would not be on Sun's forums and I would not have asked experts like you, sir !! :-)
    Neway, I got the solution from PhHein !!
    Good link indeed..
    Cheers..

  • Running OpenVMS DCL command from Java

    Hi,
    I want to execute an Alpha OpenVMS 7.2-2 command from Java. I use JDK 1.1.8-1.
    I have to place the DCL command in an OpenVMS .COM file because passing a DCL
    image like DIR doesn't work using Runtime.exec().
    When I ran the Java program, I get the following error:
    java.io.IOException: Child creation error: exec format error
    at java.lang.UNIXProcess.<init>(Compiled Code)
    at java.lang.Runtime.exec(Compiled Code)
    at java.lang.Runtime.exec(Compiled Code)
    at oscmd.main(Compiled Code)
    here is my Java program:
    import java.io.*;
    public class oscmd {
    public static void main(String[] args) throws Exception {
    Process child = Runtime.getRuntime().exec(
    "dra1:[oracle8.db_adamp.backup]RUNCMD.COM");
    child.waitFor();
    child.exitValue();
    child.destroy();
    Thanks for your help.

    Hi,
    Did you get your exec format error problem?
    I'm having exactly the same problem and would greatly appreciate any help you could offer.
    Thanks
    Tim

  • Execute DOS command from java application

    Hello,
    I want to execute a DOS command (MOVE, in order to move an image from a folder to an other) from a java application. How can I do this?
    Francesco

    Yes I have tested it and it is working but only when executing a bacth file. For instance:
    Runtime rt = Runtime.getRuntime();
    try{
         Process proc = rt.exec("move.bat");
    }catch(Exception ex){
         ex.printStackTrace();
    }and the command in move.bat is:
    move c:\\temp\\*.gif C:\\temp2
    You don't have to use double slashes in batch files, only in Java. But anyway it is working both ways.
    It is not working when you try to execute the command without the batch file:
    Process proc = rt.exec("move c:\\temp\\*.gif C:\\temp2"); -> this will not work.
    It should work. Try to execute another command to see what happens.

  • Using Unix commands from Java Application

    Hi,
    I need to write an Java application such that could run Unix commands in a Unix box.
    For example, my Java app needs to log in the Unix box, change directory (cd), create new folder (mkdir), list the current files in folder (ls), mount a new device (mount), etc.
    Thank you very much.
    Hung

    you can use java.lang.Runtime.exec to invoke OS commands, but if you're going to be completing a sequence that complicated and need to manage error handleing well, it might be best to just invoke a native method or write a shell script that does all of that stuff and then invoke that script via Runtime.exec . The Runtime class has limitations when you start invoking processes that require user input (like 'su'). Search the forums for more extensive examples on how to use Runtime.

  • Run Clear Case command from java and save the out put in to a file.

    Can any one help me out ...
    I want to execute Clear case command from a java and want to save the out put of this command to a file.
    I am naot able to find out how to start..
    Message was edited by:
    chandra_verma

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • How can I run a dos command from java on windows 98, 95?

    The usage of cmd.exe in the java program to run a dos command on windows 98. 95 doesn't work as the equivalent command is command.exe
    But using the command.exe in the java program makes my program to hang.

    hi,
    As u mentioned, u cannot use the cmd.exe in win9x environment as cmd.exe is specific to windows NT, you can use the command.exe without any hitches.
    for eg
    java.lang.Runtime.getRuntime().exec("start command /K a.bat"); should run the batch file a.bat..
    if the problem persists, try posting the snippet of code that you are using.
    cheerz
    ynkrish

  • Efficiently Running UNIX des command from Java

    Hi,
    I am trying to execute the following code in a loop to have an Brute Force attack for recovering the key.
    Runtime r = Runtime.getRuntime();
    p = r.exec("des -D -k "+keys.get(randomIndex)+ " " +cipherTextFileName);
    But as the des command has to read the file every time the programm is not a efficient one.Can I do something like reading the ciphertext from the file only once and then pass it to the des command from the java.So that it won't do I/O operations resulting good performamnce.If I can do this how to do it.Please suggest with examples.
    Thanks
    Tapas

    If you use Java you're not doing that. What does being an Academic project have to do with what tools you're allowed to use? Who is dictating that you're "only" allowed to use the des command line tool? (If it comes to that, which des command line tool are you using anyway? It's not a unix standard thing).
    The one thing you can do is to see if there is an option to read the file(s) from standard input and send them to the process from the Java runtime that way - that way the input doesn't have to be read multiple times. However this is unlikely to make any significant difference. Most of the performance cost is likely to be the context switch required to kick off the new process with very little cost incurred from re-reading a file from the disk cache.
    You've got your answer anyway. You're not going to be able to make this much more efficient. I recommend not doing that. If you really really have to, well, tough.

  • Running an ouside exe from java application

    Hi
    My application should display an help button that will open a pdf file in a browser or in acrobat reader.
    I would like to know how to start an outside applicatioon from my application.
    thanks,
    Liat

    My os is win 2000 professional
    the code:
    public static void main(String[] args) throws Exception {
    Process p = Runtime.getRuntime().exec("c:\\temp\\1.pdf");
    p.waitFor();
    System.out.println("Done.");
    and this is the exception:
    com.bitband.maestro.gui.temp.Demo1
    java.io.IOException: CreateProcess: c:\temp\1.pdf error=193
         at java.lang.Win32Process.create(Native Method)
         at java.lang.Win32Process.<init>(Win32Process.java:66)
         at java.lang.Runtime.execInternal(Native Method)
         at java.lang.Runtime.exec(Runtime.java:566)
         at java.lang.Runtime.exec(Runtime.java:428)
         at java.lang.Runtime.exec(Runtime.java:364)
         at java.lang.Runtime.exec(Runtime.java:326)
         at com.bitband.maestro.gui.temp.Demo1.main(Demo1.java:100)
    Exception in thread "main" Process terminated with exit code 1

  • CMD commands from Java applications

    I have been searching around and trying to see if it is possible to open a DOS window (via cmd) and run a command (ie: ping, tracert) from a Java GUI. I not found anything as of yet. I am familiar with Runtime.exec(); but it does not seem to like cmd. I can launch other applications, but it does not seem to launch a command window at all, and if I add any other arguements it will give me an IO error.
    Anyone have any ideas?

    Read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    It'll tell you how to use Runtime.exec() properly. MOD

  • Issues with running UNIX shell command from Java

    Here is my java class file:
    create or replace and compile java source named host as
    import java.lang.* ;
    public class Host
       public static void cmdTest()
            String cmd = "ps -ef | grep orcl" ;
            int rc = 0 ;
            int = runCmd(cmd) ;
       public static int runCmd(String str )
           Runtime rt = Runtime.getRuntime() ;
           int     rc = -1 ;
          try
                Process p = rt.exec(str) ;
                int bufSize = 4096 ;
                BufferedInputStream bis =
                    new BufferedInputStream(p.getInputStream(), bufSize) ;
                int len ;
                byte buffer[] = new byte[bufSize] ;
                // Log what the program spit out
                while ((len = bis.read(buffer, 0, bufSize)) != -1)
                    rc = p.waitFor() ;
            catch (Exception e)
                e.printStackTrace();
                rc = -1 ;
            finally
                return rc ;
    show errorsI can call runCmd directly from SQLPlus using an Oracle stored procedure and it runs like expected. I can see the returned output using dbms_java.set_output(1000000).
    But when I call cmdTest from SQLPlus using an Oracle stored procecdure it just hangs forever and I have to kill the session.
    Is there something I am missing in the cmdTest method?

    Jimmy,
    If you haven't already seen it, I think the following article may be of help:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Also a "finally" block should not contain a "return" statement:
    http://weblogs.java.net/blog/staufferjames/archive/2007/06/_dont_return_in.html
    Good Luck,
    Avi.

  • How to run system commands from JAVA

    Hi Friends,
    How to run windows system commands from JAVA
    Runtime r=Runtime.getRuntime();
    r.exec("dir");
    Throwing following Exception
    CreateProcess :dir error=2
    Thanks in advance
    Hamsa

    Hi ,
    in Windows NT this is not possible, you can use the following :
    Runtime r=Runtime.getRuntime();
    StringBuffer sbuf = new StringBuffer();
    String dir = new String();
    java.lang.Process proc = r.exec("cmd /c dir");
    InputStream is = proc.getInputStream();
    int ch ;
    while((ch=is.read() ) != -1)
    sbuf.append((char)ch);
    is.close();
    dir = sbuf.toString();
    System.out.println(dir );

  • Running a SQL*Plus command from Java

    I have a requirement to run SQL* Plus commands from Java. The results as they would appear in SQL*Plus window or spool file should be captured and stored in a table.
    For example,
    SQL> select * from dual;
    D
    X
    1 row selected;
    SQL>
    All the lines above should be stored for later use.
    Could any one give pointers?
    Thanks,
    Ravi

    <p>
    Hi,
    </p>
    <p>
    <strong><font face="Courier New">
    public class RuntimeExecApp {
     public static void main(String args[]) throws IOException
      Runtime r = Runtime.getRuntime();
      r.exec(&quot;C:\\Oracle\\sqlplus.exe&quot;);
    }</font></strong>
    </p>
    <p>
    Kuba 
    </p>
    Message was edited by:
    KUBA

  • Unable to execute Linux command from Java

    Hi,
    I am currently working on a code wherein i need to execute Linux command from Java. Below are some of the query i have.
    1) Is there any efficient method of running OS commands from Java, rather than using Runtime and Process method.
    2) Below is details of my code which fails in execution
    **-- Java Version**
    java version "1.6.0"
    OpenJDK Runtime Environment (build 1.6.0-b09)
    OpenJDK Server VM (build 1.6.0-b09, mixed mode)
    -- Program Code ----
    Where <path> = Path i put myself
    package test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.*;
    public class GetInode{
         * @param args
         public static void main(String[] args) {
              GetInode test = new GetInode();
              test.getInode();
         public void getInode(){                    
              String command = "/usr/bin/stat -Lt <path>;
              System.out.println(command);
              Process process;
              Runtime rt;     
              try{
              rt = Runtime.getRuntime();               
              process = rt.exec(command);
              InputStreamReader isr = new InputStreamReader(process.getErrorStream());
              BufferedReader bre = new BufferedReader(isr);
              BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream());
              System.out.println(bre.readLine());
    System.out.println(br.readLine().split(" ")[7]);
              process.destroy();          
              }catch (Exception ex){
                   System.out.println("Error :- " + ex.getMessage());
    ------Output -------------
    /usr/bin/stat -Lt "<path>"
    /usr/bin/stat: cannot stat `"<path>"': No such file or directory
    Error :- null
    Can any one help me what is wrong and why i am unable to run the Linux command from Java.

    For clarity purpose............i m submitting actual code here
    --- Code ---
    package test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.*;
    public class GetInode{
    * @param args
    public static void main(String[] args) {
    GetInode test = new GetInode();
    test.getInode();
    public void getInode(){               
    String command = "/usr/bin/stat -Lt \"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt\"";
    System.out.println(command);
    Process process;
    Runtime rt;
    try{
    rt = Runtime.getRuntime();
    process = rt.exec(command);
    InputStreamReader isr = new InputStreamReader(process.getErrorStream());
    BufferedReader bre = new BufferedReader(isr);
    BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
    System.out.println(bre.readLine());
    System.out.println(br.readLine().split(" ")[7]);
    process.destroy();
    }catch (Exception ex){
    System.out.println("Error :- " + ex.getMessage());
    --- Output ---
    [ratz]s0898671: java GetInode
    /usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
    /usr/bin/stat: cannot stat `"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"': No such file or directory
    Error :- null
    -- Linux Terminal --
    If i copy the first line from the output and execute on Linux terminal her is the output that i get
    [ratz]s0898671: /usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
    /afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt 12003 24 81a4 453166 10000 1c 360466554 2 0 1 1246638450 1246638450 1246638450 4096
    Can you just assist me where am i really making mistake.......i was wondering if the command that i pass from Java....can be executed on Linux terminal why is it faling to run from java.........and when i print the Error Stream for process output........it show cannot Stat.......

Maybe you are looking for

  • B200 M3 memory stuck at 1333MHz in performance mode

    Hello, We have 2 B200 M3s in a new deployment running 2.0(3a). The B200s are configured with 64GB using 8GB DIMMs, using BANK 0 of each channel. We've deployed a BIOS policy specifying performance mode for LV DDR, and confirmed this setting took effe

  • Additional functions in ECC 6.0 compared to 4.6C

    Guys, What are the additional features that we have in ECC6.0 when compared to SAP Is-Oil solution of 4.6c.

  • NetUI file upload creates temporary files without cleanup

    When using the NetUI File Upload in my web application, I notice that it stores temporary files in the server config directory. The file names are netxxxxx.tmp and they are never deleted on server startup/shutdown, etc. I am uploading large files (ab

  • Music library

    Hi there, Unfortunately, I bought nokia n 97 mini. Now suffering from music library problem... When ever I transfer new music file, it does not update the list. When I try to refresh the list, It never worked. Once I tried to refresh it in night and

  • Dll call from java using Jbuilder?

    Please? Does anyone know how I do dll calls from java (jubuilder). I have tried but did not manage to get it wright??? / thanks carlos