1 Reply Latest reply: Sep 21, 2010 7:55 AM by 750422 RSS

    Trying to use Java Stored Procedure to create  directories

    504552
      Hello, I have the followqing simple Java code I am using to run OS commands from PL SQL. When I call my function, it does not create the directory, but it does say completed successfully. Here is the code and the call I am using:
      CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED Command
      AS
      import java.io.*;
      import java.util.*;
      public class Command{
      public static void run(String cmdText)
      throws IOException, InterruptedException
      {
      try {
      int rtn;
      Runtime rt = Runtime.getRuntime();
      Process prcs = rt.exec(cmdText);
      rtn = prcs.waitFor();
      }
      catch ( Throwable ex ) {
      ex.printStackTrace();
      }
      }
      }
      /
      
      
      CREATE OR REPLACE FUNCTION runoscommand(cmd IN VARCHAR2) RETURN NUMBER
      AS LANGUAGE JAVA
      NAME 'Command.run(java.lang.String) return int';
      /
      
      
      
      DECLARE
      v_directory VARCHAR2(100):= 'C:\SYSTEM Interface\PL\files\';
      v_rtn VARCHAR2(2000);
      v_oscmd VARCHAR2(420);
       
      BEGIN
       
                  v_oscmd := 'mkdir "' || v_directory || '"';
                  dbms_output.put_line(v_oscmd);
                  SELECT runoscommand(v_oscmd) INTO v_rtn FROM DUAL;
                  dbms_output.put_line(v_rtn);
                  
      END;
      /
      Any ides on why this is not working? Any better suggestions for doing this? I need to be able to create directories from with in a PL SQL Stored Procedure. Thank you