sysLib.connect

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 syntax diagram

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

For details, see the JDBC documentation from Sun Microsystems, Inc.

Definition considerations

sysLib.connect sets the following system variables:

  • sysVar.sqlerrd[3]

  • sysVar.sqlca

  • sysVar.sqlcode

  • sysVar.sqlwarn[2]