The
system function SysLib.connect allows a program
to connect to a database at run time. This function does not return a value.
SysLib.connect(
database STRING in,
userID STRING in,
password STRING in
[, commitScope enumerationCommitScope in
[, disconnectOption enumerationDisconnectOption in
[, isolationLevel enumerationIsolationLevel in
[, commitControl enumerationCommitControlOption in
]]]] )
- database
- Identifies
a database:
- Setting database to RESET reconnects to the
default database, but if the default database is not available, the connection
status remains unchanged; for further details, see Default database.
- Otherwise, the physical database name is found by looking up the property vgj.jdbc.database.server, where server is the name of the database
specified on the SysLib.connect call. If this property
is not defined, the database name that is specified on the SysLib.connect call
is used as is.
- The format of the database name is different for J2EE connections as compared
with non-J2EE connections:
- If you generated the program for a J2EE environment, use the name to which
the datasource is bound in the JNDI registry; for example, jdbc/MyDB. This
situation occurs if build descriptor option J2EE was
set to YES.
- If you generated the program for a non-J2EE JDBC environment, use a connection
URL; for example, jdbc:db2:MyDB. This situation occurs if option J2EE was
set to NO.
- userID
- UserID used to access the database. The argument must be an item of type
CHAR and length 8, and a literal is valid. The argument is required. For background information, see Database
authorization and table names.
- password
- Password used to access the database. The argument must be an item of
type CHAR and length 8, and a literal is valid. The argument is required.
- commitScope
- The
value is one of the following words, and you cannot use quotes and cannot
use a variable:
- type1 (the default)
- Only a one-phase commit is supported. A new
connection closes all cursors, releases locks, and ends any existing connection;
nevertheless, invoke SysLib.commit or SysLib.rollback before
making a type1 connection.
If you use type1 as the value of commitScope,
the value of parameter disconnectOption must be
the word explicit, as is the default.
- type2
- A connection to a database does not close cursors, release locks, or end
an existing connection. Although you can use multiple connections to read
from multiple databases, you should update only one database in a unit of
work because only a one-phase commit is available.
- twophase
- Identical to type2.
- disconnectOption
- This parameter is meaningful only if you are generating Java™ output.
The value is one of the following words, and you cannot use quotes and cannot
use a variable:
- explicit (the default)
- The connection remains active after the program invokes SysLib.commit or SysLib.rollback.
To release connection resources, a program must issue SysLib.disconnect.
If
you use type1 as the value of commitScope, the value
of parameter disconnectOption must be set (or allowed
to default) to the word explicit.
- automatic
- A commit or rollback ends an existing connection.
- conditional
- A commit or rollback automatically ends an existing connection unless
a cursor is open and the hold option is in effect for that cursor. For details
on the hold option, see open.
- isolationLevel
- This parameter indicates the level of independence of one database transaction
from another.
The
following words are in order of increasing strictness, and as before, you
cannot use quotes and cannot use a variable:
- readUncommitted
- readCommitted
- repeatableRead
- serializableTransaction (the default value)
For details, see the JDBC documentation from Sun Microsystems,
Inc.
- commitControl
- This parameter specifies whether a commit occurs after every change to
the database.
Valid values are as follows:
- noAutoCommit (the default) means that the commit
is not automatic, which usually results in faster execution. For details on
the rules of commit and rollback in this case, see Logical unit of work.
- autoCommit means that updates take effect immediately.
You can switch from autoCommit to noAutoCommit temporarily. For
details, see SysLib.beginDatabaseTransaction.