Microsoft SDK for Java

Command Class

The Command class of the com.ms.wfc.data package defines a specific command that you intend to execute against a data source.

Use a Command object to query a database and return records in a Recordset object, to execute a bulk operation, or to manipulate the structure of a database. Depending on the functionality of the provider, some Command methods may generate an error when referenced.

With the methods of a Command object, you can do the following:

Note   To execute a query without using a Command object, pass a query string to Connection.execute or Recordset.open. A Command object is required, however, when you want to persist the command text and re-execute it, or use query parameters.

To create a Command object independently of a previously defined Connection object, pass setActiveConnection a valid connection string. ADO still creates a Connection object, but it doesn't assign that object to an object variable. However, if you are associating multiple Command objects with the same connection, you should explicitly create and open a Connection object; this assigns the Connection object to an object variable. If you do not set the Command object's setActiveConnection property to this object variable, ADO creates a new Connection object for each Command object, even if you use the same connection string.

To execute a Command, simply call it by its Name on the associated Connection object. The Command must have setActiveConnection set to the Connection object. If the Command has parameters, pass their values as arguments to the method.

If two or more Command objects are executed on the same connection and either Command object is a stored procedure with output parameters, an error occurs. To execute each Command object, use separate connections or disconnect all other Command objects from the connection.

public class Command
{
  // Methods
  public void cancel();
  public com.ms.wfc.data.Parameter createParameter(String Name, 
    int Type, int Direction, int Size, Object Value);
  public Recordset execute();
  public Recordset execute(Object[] parameters);
  public Recordset execute(Object[] parameters, int options);
  public int executeUpdate();
  public int executeUpdate(Object[] parameters);
  public int executeUpdate(Object[] parameters, int options);
  public com.ms.wfc.data.Connection getActiveConnection();
  public String getCommandText();
  public int getCommandTimeout();
  public int getCommandType();
  public String getName();
  public com.ms.wfc.data.Parameter getParameter(int n);
  public com.ms.wfc.data.Parameter getParameter(String n);
  public com.ms.wfc.data.Parameters getParameters();
  public boolean getPrepared();
  public AdoProperties getProperties();
  public int getState();
  public void setActiveConnection(com.ms.wfc.data.Connection con);
  public void setActiveConnection(String conString);
  public void setCommandText(String command);
  public void setCommandTimeout(int timeout);
  public void setCommandType(int type);
  public void setName(String name);
  public void setPrepared(boolean prepared);
}

© 1999 Microsoft Corporation. All rights reserved. Terms of use.