package examples.jdbc.informix4;

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

/**
 *This example shows how to insert string values into a column of 
 * type TEXT and then retrieve the results.
 * <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 text.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.text</b></font>
 *
 *</ol>
 *
 * @author Copyright (c) 1998-2000 by BEA Systems, Inc.  All Rights Reserved.
 */

public class text {

  public static void main(String args[]) throws Exception {

    Connection conn = null;
    Statement stmt = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    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();
    conn = myDriver.connect("jdbc:weblogic:informix4", props);

    stmt = conn.createStatement();
    try {
      stmt.execute("drop table texttest");
    }
    catch (SQLException e) {
      // table does not exist
    }
    stmt.execute("create table texttest (foo text)");

    pstmt = conn.prepareStatement("insert into texttest(foo) values (?)");

    String strval = new String("abcdefghijklmnopqrstuvwxyz");
    pstmt.setAsciiStream(1, new ByteArrayInputStream(strval.getBytes()), strval.length());
    pstmt.executeUpdate();
    System.out.println("Inserted text into a row");

    rs = stmt.executeQuery("select foo from texttest");
    rs.next();
    System.out.println("Retrieved text from a row");

    System.out.println(rs.getString(1));

  }
}
