FileDocCategorySizeDatePackage
ExecuteDDL.javaAPI DocExample1882Tue Jun 12 21:10:04 BST 2001None

ExecuteDDL

public class ExecuteDDL extends Object

Fields Summary
Connection
conn
Constructors Summary
public ExecuteDDL()

    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)

    if (args.length < 1) {
      System.err.println("Usage: java ExecuteDDL <dml file>");
      System.exit(1);
    }
    new ExecuteDDL().process(args[0]);
  
public voidprocess(java.lang.String fileName)

    boolean        rslt = false;
    BufferedReader in   = new BufferedReader(new FileReader(fileName));
    Statement      stmt = null;
    StringBuffer   sql  = new StringBuffer(1024);
    String         line = null;

    while ((line = in.readLine()) != null) { 
      System.out.println(line);
      if (line.length() == 1 && line.indexOf("/") > -1) {
        try {
          stmt = conn.createStatement();
          rslt = stmt.execute(sql.toString());
          System.out.println("OK");
          System.out.println(" ");
        }
        catch (SQLException e) {
          System.err.println(e.getMessage());
        }
        finally {
          if (stmt != null) 
            try { stmt.close(); } catch (SQLException ignore) { }
        }
        sql = new StringBuffer(1024);
      }
      else {
        sql.append(line);
        sql.append(" ");
      }
    } 
    System.out.println(sql);
    in.close();