jasp.adodb
Class Connection

java.lang.Object
  |
  +--jasp.adodb.Connection

public class Connection
extends java.lang.Object

This class is compatible with Microsoft's ADODB.CONNECTOIN object. For more usage information, please refer to Microsoft's documention.
A Connection object represents a unique session with a RDBMS. 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 JDBC Driver, some collections, methods, or properties of a Connection object may not be available.

Connection allows you to access database through JDBC Driver. Use the following syntax to set the ConnectionString.

1. If you use the JDBC driver:

Driver=drivername;URL={JDBC url};UserID=userid;Password=password; URL - a database url of the form jdbc:subprotocol:subname
UserID - the database user on whose behalf the connection is being made
Password - the password of the user.


For example: If you use Oracle JDBC driver, you can change your asp connection string as following codes:
<%
Dim DBConn
Dim strCnxn
strCnxn = "Driver=oracle.jdbc.driver.OracleDriver;" &_
"URL = {jdbc:oracle:thin:@OracleSvr:ORCL};" &_
"UserID = SCOTT;Password=TIGER;"
Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open strCnxn
%>

2. Set Connection properties to connect database

For example:
<%
Dim DBConn
Set DBConn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "org.gjt.mm.mysql.Driver"
Conn.UserName = "root"
Conn.Password = "secret"
Conn.ConnectURL = "jdbc:mysql://mySQLSvr:3306/test"
Conn.Open
%>

3. Using JDBC-ODBC bridge

If you use JDBC-ODBC bridge driver to access database:
DSN=Data Source Name;UID=userid;PWD=password
Note: You must set the JDBC driver to the CLASSPATH. J-ASP ADO only supports the JDBC2.0 or later. If you are using the JDBC1.x driver, J-ASP ADO will be not functional.


Constructor Summary
Connection()
          Creates a Connection Object.
 
Method Summary
 void AssignProps()
          Assign all properties of the Connection.
 int BeginTrans()
          Begins a new transaction.
 void Cancel()
          Terminates execution of an asynchronous Open method.
 void Close()
          Close the Connection session with database also close any active Recordset object associated with the connection.A Command object associated with the Connection object you are closing will persist, but it will no longer be associated with a Connection object; that is, its ActiveConnection property will be set to Nothing.
 void CommitTrans()
          Saves changes made within an open transaction on the connection and ends the transaction.
 Recordset Execute(java.lang.String CommandText)
          Returns a Recordset object with the specific CommandText, the CommandText maybe a SQL statement,stored procedure etc.
 Recordset Execute(java.lang.String CommandText, variant AffectedCount)
          Returns a Recordset object with the specific CommandText and return the Affected records number, the CommandText maybe a SQL statement,stored procedure etc.
 Recordset Execute(java.lang.String CommandText, variant AffectedCount, int Option)
          Returns a Recordset object with the specific CommandText and return the Affected records number, the CommandText maybe a SQL statement,stored procedure etc.
 int getAttributes()
          Returns one or more characteristics.
 int getCommandTimeout()
          Returns how long to wait while executing a command before terminating the attempt and generating an error.
 java.lang.String getConnectionString()
          Returns the information used to establish a connection to a data source.
 int getConnectionTimeout()
          Returns the value of ConnectionTimeout with current object's
 java.lang.String getConnectURL()
          Returns the url of the connection.
 int getCursorLocation()
          Returns the location of cursor engine.
 java.lang.String getDefaultDatabase()
          Returns a string value that evaluates to the name of a database available from the provider.
 Errors getErrors()
          Returns the Errors collection
 Error getErrors(int i)
          Gets an Error from the Errors Collection.
 Error getErrors(java.lang.String i)
           
 int getIsolationLevel()
          Returns the level of isolation for a Connection object.
 int getMode()
          Returns the available permissions for modifying data in a Connection.
 int getObjectState()
          Returns the objectstate of the Connection.
 java.lang.String getPassword()
          Returns the Password of the user name.
 Properties getProperties()
          Returns the properties collection of the Connection.
 java.lang.String getProvider()
          Returns the name of the Jdbc driver.
 int getState()
          Returns states of all applicable objects, open or closed.
 java.lang.String getUserName()
          Returns the user name for conecting database
 java.lang.String getVersion()
          Returns the currect the version of the ADODB.
 void Open()
          Opens a connection to a data source.
 void Open(java.lang.String connectStr)
          Opens a connection to a data source.
 void Open(java.lang.String connectStr, java.lang.String UserID)
          Opens a connection to a data source.
 void Open(java.lang.String connectStr, java.lang.String UserID, java.lang.String Password)
          Opens a connection to a data source.
 void Open(java.lang.String connectStr, java.lang.String UserID, java.lang.String Password, int Option)
          Opens a connection to a data source.
 void Open(java.lang.String connectStr, variant UserID, java.lang.String Password)
          Opens a connection to a data source.
 void Open(variant connectStr, java.lang.String UserID, java.lang.String Password, int Option)
          Opens a connection to a data source.
 void Open(variant connectStr, variant UserID, java.lang.String Password, int Option)
          Opens a connection to a data source.
 void Open(variant connectStr, variant UserID, variant Password, int Option)
          Opens a connection to a data source.
 Recordset OpenSchema(int QueryType)
          Returns a Recordset object that Obtains database schema information from the provider.
 Recordset OpenSchema(int QueryType, variant Criteria)
          Returns a Recordset object that Obtains database schema information from the provider.
 Recordset OpenSchema(int QueryType, variant Criteria, java.lang.Object SchemaID)
          Returns a Recordset object that Obtains database schema information from the provider.
 Property Properties(int index)
          Gets a property with specific index from Properties collection
 Property Properties(java.lang.String name)
          Returns the Property object with specific name from Properties collection
 Property Properties(variant var)
          Gets a property from the Properties collection.
 void RollbackTrans()
          Reverses any changes made within an open transaction and ends the transaction if the Attributes property is set to adXactAbortRetaining, it automatically starts a new transaction after a RollbackTrans call
 void setAttributes(int attrib)
          Indicates one or more characteristics of an object.
 void setCommandTimeout(int cmdtimeout)
          Sets the CommandTimeout property value
 void setConnectionString(java.lang.String connectStr)
          Sets the information for establish a connection

Note: the connection must be following format:
Using jdbc-odbc bridge:
"DSN=Data Source Name;UID=userid;PWD=password" Using JDBC Drivers:
"Driver=drivername;URL={JDBC url};UserID=userid;Password=password;"
 void setConnectionTimeout(int timeout)
          Sets the ConnectionTimeout's value for the currect object.
 void setConnectURL(java.lang.String url)
          Sets the url of the Connection
 void setCursorLocation(int cursorlocation)
          Sets the location of the cursor engine.
 void setDefaultDatabase(java.lang.String db)
          Sets a string value the evaluates to the name of a database avaliable from the provider.
 void setIsolationLevel(int islevel)
          Sets the level of isolation for a Connection object.
 void setMode(int mode)
          Sets the available permissions for connection.
 void setPassword(java.lang.String password)
          Sets the password of the username.
 void setProvider(java.lang.String provider)
          Sets the name of jdbc driver.
 void setUserName(java.lang.String username)
          Set the user name for conecting database.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Connection

public Connection()
Creates a Connection Object.
Method Detail

getVersion

public java.lang.String getVersion()
                            throws java.lang.Exception
Returns the currect the version of the ADODB.

setConnectURL

public void setConnectURL(java.lang.String url)
                   throws java.lang.Exception
Sets the url of the Connection
Parameters:
url - the url of JDBC Driver for connecting database.

getConnectURL

public java.lang.String getConnectURL()
Returns the url of the connection.

setUserName

public void setUserName(java.lang.String username)
                 throws java.lang.Exception
Set the user name for conecting database.

getUserName

public java.lang.String getUserName()
Returns the user name for conecting database

getPassword

public java.lang.String getPassword()
Returns the Password of the user name.

setPassword

public void setPassword(java.lang.String password)
                 throws java.lang.Exception
Sets the password of the username.

getDefaultDatabase

public java.lang.String getDefaultDatabase()
                                    throws java.lang.Exception
Returns a string value that evaluates to the name of a database available from the provider.

setDefaultDatabase

public void setDefaultDatabase(java.lang.String db)
                        throws java.lang.Exception
Sets a string value the evaluates to the name of a database avaliable from the provider.

getConnectionTimeout

public int getConnectionTimeout()
Returns the value of ConnectionTimeout with current object's

setConnectionTimeout

public void setConnectionTimeout(int timeout)
                          throws java.lang.Exception
Sets the ConnectionTimeout's value for the currect object.

getState

public int getState()
Returns states of all applicable objects, open or closed. the state can be one of following constants.
  1. adStateClosed default. Indicates the object is closed.
  2. adStateOpen Indicates that the object is open.
  3. adStateConnection Indicates that the Recordset object is connecting.
  4. adStateExecuting Indicates that the Recordset object is executing a command.
  5. adStateFetching Indicates that the rows of the Recordset object are being fetched.

getMode

public int getMode()
Returns the available permissions for modifying data in a Connection. the Mode can be one of the following constants.
  1. adModeUnknown Default. Indicates that the permissions have not yet been set or cannot be determined.
  2. adModeRead Indicates read-only permissions.
  3. adModeWrite Indicates write-only permissions.
  4. adModeReadWrite Indicates read/write permissions.
  5. adModeShareDenyRead Prevents others from opening connection with read permissions.
  6. adModeShareDenyWrite Prevents others from opening connection with write permissions
  7. adModeShareExclusive Prevents others from opening connection.
  8. adModeShareDenyNone Prevents others from opening connection with any permissions.
  9. adModeRecursive

setMode

public void setMode(int mode)
             throws java.lang.Exception
Sets the available permissions for connection.

getProvider

public java.lang.String getProvider()
Returns the name of the Jdbc driver.

setProvider

public void setProvider(java.lang.String provider)
                 throws java.lang.Exception
Sets the name of jdbc driver.

getAttributes

public int getAttributes()
Returns one or more characteristics.
  1. adXactCommitRetaining Performs retaining commits¡ªthat is, calling CommitTrans automatically starts a new transaction.
  2. adXactAbortRetaining Performs retaining aborts¡ªthat is, calling RollbackTrans automatically starts a new transaction.

setAttributes

public void setAttributes(int attrib)
Indicates one or more characteristics of an object.

getCursorLocation

public int getCursorLocation()
Returns the location of cursor engine.
  1. adUseClient Uses client-side cursors supplied by a local cursor library.
  2. adUseServer Default, Uses data-provider¨C or driver-supplied cursors. These cursors are sometimes very flexible and allow for additional sensitivity to changes others make to the data source

setCursorLocation

public void setCursorLocation(int cursorlocation)
                       throws java.lang.Exception
Sets the location of the cursor engine. It's Read/Write on a Connection.

getCommandTimeout

public int getCommandTimeout()
Returns how long to wait while executing a command before terminating the attempt and generating an error.

setCommandTimeout

public void setCommandTimeout(int cmdtimeout)
Sets the CommandTimeout property value

getConnectionString

public java.lang.String getConnectionString()
Returns the information used to establish a connection to a data source.

setConnectionString

public void setConnectionString(java.lang.String connectStr)
                         throws java.lang.Exception
Sets the information for establish a connection

Note: the connection must be following format:

Parameters:
connectStr - a string value

getIsolationLevel

public int getIsolationLevel()
Returns the level of isolation for a Connection object.
  • adXactUnspecified Indicates that the provider is using a different IsolationLevel than specified, but that the level cannot be determined.
  • adXactChaos Default. Indicates that you cannot overwrite pending changes from more highly isolated transactions.
  • adXactBrowse Indicates that from one transaction you can view uncommitted changes in other transactions.
  • adXactReadUncommitted Same as adXactBrowse.
  • adXactCursorStability Default. Indicates that from one transaction you can view changes in other transactions only after they've been committed.
  • adXactReadCommitted Same as adXactCursorStability.
  • adXactRepeatableRead Indicates that from one transaction you cannot see changes made in other transactions, but that requerying can bring new recordsets.
  • adXactIsolated Indicates that transactions are conducted in isolation of other transactions
  • adXactSerializable Same as adXactIsolated

  • setIsolationLevel

    public void setIsolationLevel(int islevel)
    Sets the level of isolation for a Connection object.

    getProperties

    public Properties getProperties()
                             throws java.lang.Exception
    Returns the properties collection of the Connection.

    getObjectState

    public int getObjectState()
    Returns the objectstate of the Connection.

    AssignProps

    public void AssignProps()
                     throws java.lang.Exception
    Assign all properties of the Connection.

    Properties

    public Property Properties(variant var)
                        throws java.lang.Exception
    Gets a property from the Properties collection.
    Parameters:
    var - the name or index of the property.
    Returns:
    a Property value.

    Properties

    public Property Properties(int index)
                        throws java.lang.Exception
    Gets a property with specific index from Properties collection
    Parameters:
    index - the index of the property.
    Returns:
    a Property value

    Properties

    public Property Properties(java.lang.String name)
                        throws java.lang.Exception
    Returns the Property object with specific name from Properties collection
    Parameters:
    name - the name of the property.
    Returns:
    a Property value

    getErrors

    public Errors getErrors()
    Returns the Errors collection

    getErrors

    public Error getErrors(int i)
                    throws java.lang.Exception
    Gets an Error from the Errors Collection.
    Parameters:
    i - the index of the error.
    Returns:
    an error.

    getErrors

    public Error getErrors(java.lang.String i)
                    throws java.lang.Exception

    OpenSchema

    public Recordset OpenSchema(int QueryType)
                         throws java.lang.Exception
    Returns a Recordset object that Obtains database schema information from the provider.
    Parameters:
    QueryType - The type of schema query to run.
    Returns:
    a Recordset object that contains schema information.

    OpenSchema

    public Recordset OpenSchema(int QueryType,
                                variant Criteria,
                                java.lang.Object SchemaID)
                         throws java.lang.Exception
    Returns a Recordset object that Obtains database schema information from the provider.
    Parameters:
    QueryType - The type of schema query to run.
    Criteria - An array of query constraints for each QueryType option.
    SchemaID - The GUID for a provider-schema schema query not defined by the OLE DB specification.(Don't use it in J-ASP).
    Returns:
    a Recordset object that contains schema information.

    OpenSchema

    public Recordset OpenSchema(int QueryType,
                                variant Criteria)
                         throws java.lang.Exception
    Returns a Recordset object that Obtains database schema information from the provider.
    Parameters:
    QueryType - The type of schema query to run.
    Criteria - An array of query constraints for each QueryType option.
    Returns:
    a Recordset object that contains schema information.

    Close

    public void Close()
               throws java.lang.Exception
    Close the Connection session with database also close any active Recordset object associated with the connection.A Command object associated with the Connection object you are closing will persist, but it will no longer be associated with a Connection object; that is, its ActiveConnection property will be set to Nothing. Also, the Command object's Parameters collection will be cleared of any provider-defined parameters.

    Execute

    public Recordset Execute(java.lang.String CommandText)
                      throws java.lang.Exception
    Returns a Recordset object with the specific CommandText, the CommandText maybe a SQL statement,stored procedure etc.
    Parameters:
    CommandText - A String containing the SQL statement, table name, stored procedure, or provider-specific text to execute
    Returns:
    a Recordset object.

    Execute

    public Recordset Execute(java.lang.String CommandText,
                             variant AffectedCount)
                      throws java.lang.Exception
    Returns a Recordset object with the specific CommandText and return the Affected records number, the CommandText maybe a SQL statement,stored procedure etc.
    Parameters:
    CommandText - A String containing the SQL statement, table name, stored procedure, or provider-specific text to execute
    AffectedCount - the provider returns the number of records that the operation affected.
    Returns:
    a Recordset object.

    Execute

    public Recordset Execute(java.lang.String CommandText,
                             variant AffectedCount,
                             int Option)
                      throws java.lang.Exception
    Returns a Recordset object with the specific CommandText and return the Affected records number, the CommandText maybe a SQL statement,stored procedure etc.
    Parameters:
    CommandText - A String containing the SQL statement, table name, stored procedure, or provider-specific text to execute
    AffectedCount - the provider returns the number of records that the operation affected.
    Option - An integer value that indicates how the provider should evaluate the CommandText argument.
    Returns:
    a Recordset object.

    Open

    public void Open()
              throws java.lang.Exception
    Opens a connection to a data source.

    Open

    public void Open(java.lang.String connectStr)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A String containing connection information. See the ConnectionString property for details on valid settings

    Open

    public void Open(java.lang.String connectStr,
                     java.lang.String UserID)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A String containing connection information. See the ConnectionString property for details on valid settings
    UserID - A String containing a user name to use when establishing the connection.

    Open

    public void Open(java.lang.String connectStr,
                     java.lang.String UserID,
                     java.lang.String Password)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A String containing connection information. See the ConnectionString property for details on valid settings
    UserID - A String containing a user name to use when establishing the connection.
    Password - A String containing a password to use when establishing the connection.

    Open

    public void Open(java.lang.String connectStr,
                     variant UserID,
                     java.lang.String Password)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A String containing connection information. See the ConnectionString property for details on valid settings
    UserID - A variant containing a user name to use when establishing the connection.
    Password - A String containing a password to use when establishing the connection.

    Open

    public void Open(variant connectStr,
                     variant UserID,
                     variant Password,
                     int Option)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A variant containing connection information. See the ConnectionString property for details on valid settings
    UserID - A variant containing a user name to use when establishing the connection.
    Password - A variant containing a password to use when establishing the connection.

    Open

    public void Open(variant connectStr,
                     variant UserID,
                     java.lang.String Password,
                     int Option)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A variant containing connection information. See the ConnectionString property for details on valid settings
    UserID - A variant containing a user name to use when establishing the connection.
    Password - A String containing a password to use when establishing the connection.

    Open

    public void Open(variant connectStr,
                     java.lang.String UserID,
                     java.lang.String Password,
                     int Option)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A variant containing connection information. See the ConnectionString property for details on valid settings
    UserID - A String containing a user name to use when establishing the connection.
    Password - A String containing a password to use when establishing the connection.

    Open

    public void Open(java.lang.String connectStr,
                     java.lang.String UserID,
                     java.lang.String Password,
                     int Option)
              throws java.lang.Exception
    Opens a connection to a data source.
    Parameters:
    connectStr - A String containing connection information. See the ConnectionString property for details on valid settings
    UserID - A String containing a user name to use when establishing the connection.
    Password - A String containing a password to use when establishing the connection.

    Cancel

    public void Cancel()
    Terminates execution of an asynchronous Open method.

    BeginTrans

    public int BeginTrans()
                   throws java.lang.Exception
    Begins a new transaction.
    Returns:
    an integer value, if the Provider supports nested transactions, return value indicates the level of nesting.

    CommitTrans

    public void CommitTrans()
                     throws java.lang.Exception
    Saves changes made within an open transaction on the connection and ends the transaction. if the Attributes property is set to adXactCommitRetaining, it automatically starts a new transaction

    RollbackTrans

    public void RollbackTrans()
                       throws java.lang.Exception
    Reverses any changes made within an open transaction and ends the transaction if the Attributes property is set to adXactAbortRetaining, it automatically starts a new transaction after a RollbackTrans call

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object