package examples.jdbc.informix4;

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

/**
 * 
 *This simple example shows how data and result set metadata
 * is selected with JDBC.
 * It assumes the table <tt>empdemo exists</tt>. This table is created
 * in the <a href=examples.jdbc.informix4.simplesql.html><font
 *face="Courier New" size=-1>simplesql</font></a> 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 simpleselect.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.simpleselect</b></font>
 *
 *</ol>
 *
 * @author Copyright (c) 1996-2000 by BEA Systems, Inc.  All Rights Reserved.
 */

public class simpleselect {
  
  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();
    
      stmt.execute("select * from empdemo");
    
      ResultSet rs = stmt.getResultSet();
    
      while (rs.next()) {
          System.out.println(rs.getString("empid") + " - " + 
                             rs.getString("name")  + " - " + 
                             rs.getString("dept"));
      }
    
      ResultSetMetaData rsmd = rs.getMetaData();
      
      System.out.println("Number of Columns: " + rsmd.getColumnCount());
      for (int i = 1; i <= rsmd.getColumnCount(); i++) {
          System.out.println("Column Name: "          + rsmd.getColumnName(i));
          System.out.println("Nullable: "             + rsmd.isNullable(i));
          System.out.println("Precision: "            + rsmd.getPrecision(i));
          System.out.println("Scale: "                + rsmd.getScale(i));
          System.out.println("Size: "                 + rsmd.getColumnDisplaySize(i));
          System.out.println("Column Type: "          + rsmd.getColumnType(i));
          System.out.println("Column Type Name: "     + rsmd.getColumnTypeName(i));
          System.out.println("");
      }
      
      stmt.close();
      conn.close();
  }
}

