package examples.jdbc.oracle;

import java.sql.*;
import java.util.Properties;

/**
 * This simple example shows how to execute DDL and DML via JDBC.
 * <p>
 * This example is run on the command line and is output to
 * System.out.
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=../techstart/environment.html>Setting up your environment</a>.
 *<p>
 *<li> Change connection parameters to correspond to your Oracle configuration.
 * If you need more help, check the section on connecting
 *to a database in the Developers Guide, <a
 *href=../../../classdocs/API_joci.html>Using WebLogic jDriver for Oracle</a>.
 *<p>
 *
 *<li>Compile this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ javac -d %CLIENT_CLASSES% simplesql.java</b></font>
 *<p>	
 *
 *<li>Run this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ java examples.jdbc.oracle.simplesql</b></font>
 *
 *</ol> *
 * @author Copyright (c) 1996-2000 by BEA Systems, Inc.  All Rights Reserved.
 */

public class simplesql {
  
  public static void main(String argv[])
       throws Exception
  {
    Properties props = new Properties();
    props.put("user","scott");
    props.put("password","tiger");
    props.put("server","DEMO");

    Driver myDriver = (Driver) Class.forName("weblogic.jdbc.oci.Driver").newInstance();
    Connection conn = myDriver.connect("jdbc:weblogic:oracle", props);
    
    Statement stmt = conn.createStatement();
    
    try {
      stmt.execute("drop table empdemo");
      System.out.println("Table empdemo dropped.");
    }
    catch (SQLException e) {
      System.out.println("Table empdemo doesn't need to be dropped.");
    }
    
    stmt.execute("create table empdemo (empid integer, name varchar2(30), dept number(4))");
    System.out.println("Table empdemo created.");
    
    int numrows = stmt.executeUpdate("insert into empdemo values (0, 'John Smith', 12)");
    System.out.println("Number of rows inserted = " + numrows);
    
    numrows = stmt.executeUpdate("delete from empdemo where empid = 0");
    System.out.println("Number of rows deleted = " + numrows);
    
    stmt.close();
    conn.close();
  }
}

