FileDocCategorySizeDatePackage
DescribeStoredProcedures.javaAPI DocExample3449Wed Jul 11 14:39:58 BST 2001None

DescribeStoredProcedures

public class DescribeStoredProcedures extends Object

Fields Summary
Connection
conn
Constructors Summary
public DescribeStoredProcedures()

    try {
      DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
      conn = DriverManager.getConnection(
       "jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    }
  
Methods Summary
protected voidfinalize()

    if (conn != null) 
      try { conn.close(); } catch (SQLException ignore) { }
    super.finalize();
  
public static voidmain(java.lang.String[] args)

    String storedProcedureName = null;
    String schemaName          = null;
    if (args.length > 0) 
      schemaName          = args[0];
    if (args.length > 1) 
      storedProcedureName = args[1];
    new DescribeStoredProcedures().process(schemaName, storedProcedureName);
  
public voidprocess(java.lang.String schemaName, java.lang.String storedProcedureName)


    int rows                    = 0;
    ResultSet rslt              = null;
    Statement stmt              = null;
    String previous             = "~";
    String schemaPattern        = "%";
    String procedureNamePattern = "%";

    try {
      if (schemaName != null && !schemaName.equals("")) 
        schemaPattern = schemaName;
      if (storedProcedureName != null && !storedProcedureName.equals("")) 
        procedureNamePattern = storedProcedureName;
      stmt = conn.createStatement();
      rslt = stmt.executeQuery(
       "select type||' '||owner||'.'||name, line, text " + 
       "from   sys.dba_source " + 
       "where  type = 'FUNCTION' " + 
       "and    owner like '" + schemaPattern + "' " +
       "and    name  like '" + procedureNamePattern + "' " + 
       "union all " +
       "select type||' '||owner||'.'||name, line, text " + 
       "from   sys.dba_source " + 
       "where  type = 'PROCEDURE' " + 
       "and    owner like '" + schemaPattern + "' " +
       "and    name  like '" + procedureNamePattern + "' " + 
       "union all " +
       "select type||' '||owner||'.'||name, line, text " + 
       "from   sys.dba_source " + 
       "where  type = 'PACKAGE' " + 
       "and    owner like '" + schemaPattern + "' " +
       "and    name  like '" + procedureNamePattern + "' " + 
       "union all " +
       "select type||' '||owner||'.'||name, line, text " + 
       "from   sys.dba_source " + 
       "where  type = 'TYPE' " + 
       "and    owner like '" + schemaPattern + "' " +
       "and    name  like '" + procedureNamePattern + "' " + 
       "order by 1, 2");
      while (rslt.next()) {
        rows++;
        if (!rslt.getString(1).equals(previous)) {
          if (!previous.equals("~"))
          System.out.println("");
          previous = rslt.getString(1);
        }
        System.out.print(rslt.getString(3));
      }
      if (!previous.equals("~"))
        System.out.println("");
    }
    catch (SQLException e) {
      System.err.println("SQL Error: " + e.getMessage());
    }
    finally {
      if (rslt != null)  
        try { rslt.close();  } catch (SQLException ignore) { }
      if (stmt != null)  
        try { stmt.close();  } catch (SQLException ignore) { }
    }