Microsoft SDK for Java

Connection Class

The Connection class of the com.ms.wfc.data package represents a unique session with a data source. In the case of a client/server database system, it may be equivalent to an actual network connection to the server. Depending on the functionality supported by the provider, some collections, methods, or properties of a Connection object may not be available.

public class Connection
{
  // Methods
  public void addOnBeginTransComplete(ConnectionEventHandler handler);
  public void addOnCommitTransComplete(ConnectionEventHandler handler);
  public void addOnConnectComplete(ConnectionEventHandler handler);
  public void addOnDisconnect(ConnectionEventHandler handler);
  public void addOnExecuteComplete(ConnectionEventHandler handler);
  public void addOnInfoMessage(ConnectionEventHandler handler);
  public void addOnRollbackTransComplete(ConnectionEventHandler handler);
  public void addOnWillConnect(ConnectionEventHandler handler);
  public void addOnWillExecute(ConnectionEventHandler handler);
  public int beginTrans();
  public void cancel();
  public void close();
  public void commitTrans();
  public com.ms.wfc.data.Recordset execute(String commandText);
  public com.ms.wfc.data.Recordset execute(String commandText, int options);
  public int executeUpdate(String commandText);
  public int executeUpdate(String commandText, int options);
  public int getAttributes();
  public int getCommandTimeout();
  public String getConnectionString();
  public int getConnectionTimeout();
  public int getCursorLocation();
  public String getDefaultDatabase();
  public com.ms.wfc.data.Errors getErrors();
  public int getIsolationLevel();
  public int getMode();
  public AdoProperties getProperties();
  public String getProvider();
  public int getState();
  public String getVersion();
  public void open(); 
  public void open(String connectionString);
  public void open(String connectionString, String userID);
  public void open(String connectionString, String userID, String password);
  public void open(String connectionString, String userID, String password, int options);
  public Recordset openSchema(int schema);
  public Recordset openSchema(int schema, Object[] restrictions);
  public Recordset openSchema(int schema, Object[] restrictions, String schemaID);
  public void rollbackTrans();
  public void setAttributes(int attr);
  public void setCommandTimeout(int timeout);
  public void setConnectionString(String con);
  public void setConnectionTimeout(int timeout);
  public void setCursorLocation(int cursorLoc);
  public void setDefaultDatabase(String db);
  public void setIsolationLevel(int level);
  public void setMode(int mode);
  public void setProvider(String provider);
}

Using the methods of a Connection object, you can do the following:

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

You can create Connection objects independently of any other previously defined object.

Note   You can execute commands or stored procedures as if they were native methods on the Connection object.

To execute a command, give the command a name using the Command object setName property. Pass the Command object's setActiveConnection value to the connection. Then issue a statement where the command name is used as if it were a method on the Connection object, followed by any parameters, followed by a Recordset object if any rows are returned. Set the Recordset properties to customize the resulting Recordset.

To execute a stored procedure, issue a statement where the stored procedure name is used as if it were a method on the Connection object, followed by any parameters. ADO will make a "best guess" of parameter types.

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