FileDocCategorySizeDatePackage
DescribeStoredProcedure.javaAPI DocExample3125Wed Jan 03 19:43:16 GMT 2001None

DescribeStoredProcedure

public class DescribeStoredProcedure extends Object

Fields Summary
Connection
conn
Constructors Summary
public DescribeStoredProcedure()

  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 packageName         = null;
  String schemaName          = null;
  if (args.length > 0) 
   schemaName          = args[0];
  if (args.length > 2) {
   packageName         = args[1];
   storedProcedureName = args[2];
  }
  else if (args.length > 1){
   storedProcedureName = args[1];
  }
  new DescribeStoredProcedure().process(
   schemaName, packageName, storedProcedureName);
 
public voidprocess(java.lang.String schemaName, java.lang.String packageName, java.lang.String storedProcedureName)

  int rows                    = 0;
  ResultSet rslt              = null;
  String previous             = "~";
  String catalog              = null;
  String schemaPattern        = "%";
  String procedureNamePattern = "%";
  try {
   if (schemaName != null && !schemaName.equals("")) 
    schemaPattern = schemaName;
   if (packageName != null && !packageName.equals("")) 
    catalog = packageName;
   if (storedProcedureName != null && !storedProcedureName.equals("")) 
    procedureNamePattern = storedProcedureName;
   rslt = conn.getMetaData().getProcedureColumns(
    catalog,
    schemaPattern,
    procedureNamePattern,
    "%" );
   while (rslt.next()) {
    rows++;
    if (!rslt.getString(3).equals(previous)) {
     if (!previous.equals("~"))
      System.out.println(")");
     previous = rslt.getString(3);
     if (rslt.getString(1) != null) {
      System.out.println(rslt.getString(2) + 
       "." + rslt.getString(1) + 
       "." + rslt.getString(3) + "(");
     }
     else {
      System.out.println(rslt.getString(2) + 
       "." + rslt.getString(3) + "(");
     }
    }
    else {
     System.out.println(",");
    }
    System.out.print(rslt.getString(4) + " ");
    switch (rslt.getInt(5)) {
     case DatabaseMetaData.procedureColumnIn:
      System.out.print("in     ");
      break;
     case DatabaseMetaData.procedureColumnOut:
      System.out.print("   out ");
      break;
     case DatabaseMetaData.procedureColumnInOut:
      System.out.print("in out ");
    }
    System.out.print(rslt.getString(7));
   }
   if (rows > 1 && !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) { }
  }