package examples.jdbc.informix4;

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.
 *
 * @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",     "informix");
      props.put("password", "secret");
      props.put("server",   "myDBHost"); // hostname on which Informix server runs
      props.put("port",     "1493");       // port on which Informix server listens
      props.put("db",       "myDB");  // name of database on Informix server
      
      
      Driver myDriver = (Driver) Class.forName("weblogic.jdbc.informix4.Driver").newInstance();
      Connection conn = myDriver.connect("jdbc:weblogic:informix4", props);
      
      Statement stmt = conn.createStatement();
      
      try {
          stmt.execute("drop table empdemo");
          System.out.println("Table empdemo dropped.");
      }
      catch (SQLException e) {
          // Table empdemo doesn't need to be dropped.
      }
      
      stmt.execute("create table empdemo (empid integer, name varchar(30), dept float(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);
      
      // If Database is not in AutoCommit mode, then be sure to commit work
      if (!conn.getAutoCommit()) {
          conn.commit();
      }
      
      stmt.close();
      conn.close();
  }
}

