package examples.jdbc.informix4;

import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.Properties;


/** This applet opens a connection to a database and executes the
 * simple SQL statement 'select count(*) from systables'.  
 *
 * <p> If this test fails, make sure that SocketApplet and
 * ConnectionApplet work before you proceed.
 *Using the Java utility <b>Appletviewer</b> allows the applet
 *to run without security restrictions.
 * <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 SelectApplet.java</b></font>
 *<p>	
 *
 *<li>Run this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ appletviewer SelectApplet.html</b></font>
 *
 *</ol>
 *
 * @author Copyright (c) 1997-2000 by BEA Systems, Inc. All Rights Reserved. 
 */

public class SelectApplet extends Applet
{
  
  public void init()
  {
      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
      
      try
          {
              Driver myDriver = (Driver) Class.forName("weblogic.jdbc.informix4.Driver").newInstance();        
              
              // Select a driver, then open a connection to the database
              Connection connection = myDriver.connect("jdbc:weblogic:informix4", props);    
              
              // Send a select and retrieve the result set, a row with one column.
              Statement statement = connection.createStatement();
              statement.execute("select count(*) from systables");
              
              // Process results of the select. 
              ResultSet result = statement.getResultSet();
              while (result.next()) {
                  message =  result.getString(1) ;
              }
              message = "SQL query succeeded: " + message + " tables in this database."; 
          }
      catch(Exception ex)
          {
              message = "Exception during SQL query: " + ex;
              ex.printStackTrace(System.out);
          }
      
      System.out.println(message);
      repaint();
  }
    
    /**
     * A method to display the message in the applet.
     *
     */
    public void paint(Graphics graphics)
    {
        graphics.drawString(message,10,20);
    }
    
    String message = "";
}














