FileDocCategorySizeDatePackage
GetStoredProcedures.javaAPI DocExample2331Wed Jan 03 19:21:58 GMT 2001None

GetStoredProcedures.java

import java.io.*;
import java.sql.*;
import java.text.*;

public class GetStoredProcedures {
 Connection conn;
 public GetStoredProcedures() {
  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();
  }
 }

 public static void main(String[] args) 
  throws Exception, IOException {
  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 GetStoredProcedures().process(
   schemaName, packageName, storedProcedureName);
 }

 public void process(
  String schemaName, 
  String packageName, 
  String storedProcedureName) 
  throws SQLException {
  int row                     = 0;
  ResultSet rslt              = null;
  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().getProcedures(
    catalog,
    schemaPattern,
    procedureNamePattern );
   while (rslt.next()) {
    row++;
    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));
   }
  }
  catch (SQLException e) {
   System.err.println("SQL Error: " + e.getMessage());
  }
  finally {
   if (rslt != null)  
    try { rslt.close();  } catch (SQLException ignore) { }
  }
 }

 protected void finalize() 
  throws Throwable {
  if (conn != null) { try { conn.close(); } catch (SQLException ignore) { } }
  super.finalize();
 }
}