package examples.jdbc.mssqlserver4;

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 1'.
 * <p>
 * If this test fails, make sure that SocketApplet and
 * ConnectionApplet work before you proceed.
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=Package-examples.jdbc.mssqlserver4.html>Package examples.jdbc.mssqlserver4</a>.
 *<p>
 *<li> In the <font face="Courier New" size=-1>SelecttApplet.java</font>
 *file, change the database URL, login, and password connection
 *parameters to correspond to your Microsoft SQL Server
 *configuration.  If you need more help, check
 *the section on connecting to a database in the Developers Guide, <a
 *href=../../../classdocs/API_jmsq4.html>Using
 *WebLogic jDriver for Microsoft SQL Server</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/mssqlserver4/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()
  {
      // Change the username, password, and server to your database login account.  
      Properties props = new Properties();
      props.put("user", "sa");
      props.put("password", "secret");
      props.put("server", "myHost:1433");

      Driver myDriver = null;    
      try
      {
      myDriver = (Driver) Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();

        // Select a driver, then open a connection to the database
        Connection connection = myDriver.connect("jdbc:weblogic:mssqlserver4", props);    
        
        // A very simple query...
        PreparedStatement statement = connection.prepareStatement("select 1");      

        // Send the query and retrieve the result set, a table with one row and column.
        ResultSet result = statement.executeQuery();

        // The following message prints only if no exception is raised.
        message = "SQL query was successful."; 
      }

    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 = "";
}














