FileDocCategorySizeDatePackage
JdbcApplet.javaAPI DocExample2754Tue Jul 29 18:07:04 BST 1997None

JdbcApplet

public class JdbcApplet extends Applet

Fields Summary
static final String
driver_class
static final String
connect_string
static final String
query
Button
execute_button
TextArea
output
Connection
conn
Constructors Summary
Methods Summary
public booleanaction(java.awt.Event ev, java.lang.Object arg)

    if (ev.target == execute_button)
    {
      try
      {
	// Clear the output area
	output.setText (null);

	// See if we need to open the connection to the database
	if (conn == null)
	{
	  // Load the JDBC driver
	  output.appendText ("Loading JDBC driver " + driver_class + "\n");
	  Class.forName (driver_class);

	  // Connect to the databse
	  output.appendText ("Connecting to " + connect_string + "\n");
	  conn = DriverManager.getConnection (connect_string);
	  output.appendText ("Connected\n");
	}

	// Create a statement
	Statement stmt = conn.createStatement ();

	// Execute the query
	output.appendText ("Executing query " + query + "\n");
	ResultSet rset = stmt.executeQuery (query);

	// Dump the result
	while (rset.next ())
	  output.appendText (rset.getString (1) + "\n");

	// We're done
	output.appendText ("done.\n");
      }
      catch (Exception e)
      {
	// Oops
	output.appendText (e.getMessage () + "\n");
      }
      return true;
    }
    else
      return false;
  
public voidinit()


  // Create the User Interface
     
  
    this.setLayout (new BorderLayout ());
    Panel p = new Panel ();
    p.setLayout (new FlowLayout (FlowLayout.LEFT));
    execute_button = new Button ("Hello JDBC");
    p.add (execute_button);
    this.add ("North", p);
    output = new TextArea (10, 60);
    this.add ("Center", output);