package examples.jdbc.informix4;

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

/**
 *
 * This simple example shows how JDBC is used to execute DDL and
 * DML. It assumes the table <tt>empdemo</tt> exists. This table is created
 * in the simplesql example.
 * <p>
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=Package-examples.jdbc.informix4.html>Package examples.jdbc.informix4</a>.
 *<p>
 *<li> Change connection parameters to correspond to your Informix
 *Dynamic Server configuration.  If you need more help, check the section on
 *connecting to a database in the Developers Guide, <a
 *href=../../../classdocs/API_jinf4.html>Using WebLogic jDriver for Informix</a>.
 *
 *<p>
 *
 *<li>Compile this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ javac -d c:/weblogic/informix4/classes records.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.informix4.records</b></font>
 *
 *</ol>
 *
 * 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 records {
  
  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);
    
    // Insert 100 records
    System.out.println("Inserting 100 records...");
    String inssql = "insert into empdemo(empid, name, dept) values (?, ?, ?)";
    PreparedStatement pstmt = conn.prepareStatement(inssql);
    
    for (int i = 0; i < 100; i++) {
      pstmt.setInt(1, i);
      pstmt.setString(2, "Person " + i);
      pstmt.setInt(3, i);
      pstmt.execute();
    }
    
    pstmt.close();
    
    // Update 100 records
    System.out.println("Updating 100 records...");
    String updsql = "update empdemo set dept = dept + ? where empid = ?";
    PreparedStatement pstmt2 = conn.prepareStatement(updsql);
    
    for (int i = 0; i < 100; i++) {
      pstmt2.setInt(1, i);
      pstmt2.setInt(2, i);
      pstmt2.execute();
    }
    pstmt2.close();
    
    // if this Database is not in autocommit mode, then commit the work
    if (!conn.getAutoCommit()) {
      conn.commit();
    }
    
    conn.close();
  }
  
}










