The
system function
VGLib.connectionService provides
two benefits:
- Allows a program to connect or disconnect to a database at run time.
- Receives (optionally) the database product name and release level. You
can use the received information in a case, if,
or while statement so that runtime processing is
dependent on characteristics of the database.
When you use VGLib.connectionService to create
a new connection from a Java™ program, specify the isolation
level by setting the system variable VGVar.sqlIsolationLevel.
VGLib.connectionService is for use only in programs
migrated from VisualAge® Generator
and EGL 5.0. The function is supported (at development time) if the EGL preference VisualAge
Generator compatibility is selected or (at generation time)
if the build descriptor option VAGCompatibility is
set to yes.
For new programs, use these system functions instead:
VGLib.connectionService does not return a value.
VGLib.connectionService(
userID CHAR(8) in,
password CHAR(8) in,
serverName CHAR(18) in
[, product CHAR(8) inOut,
release CHAR(8) inOut
[, connectionOption STRING in
]])
- userID
- UserID used to access the database. The argument must be an item of type
CHAR and length 8; a literal is not 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; a literal is not valid. The argument is required.
- serverName
- Specifies a connection and uses that connection to assign values to the
arguments product and release,
if those arguments are included in the invocation of VGLib.connectionService.
The argument
serverName is required and must
be an item of type CHAR and length 18. Any of the following values are valid:
- blanks (no content)
- If a connection is in place, VGLib.connectionService maintains
that connection. If a connection is not in place, the result (other than to
assign values) is to return to the connection status that is in effect at
the beginning of a run unit, as described in Default database.
- RESET
- 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.
- serverName
- Identifies
a database:
- The physical database name is found by looking up the property vgj.jdbc.database.server,
where server is the name of the server specified
on the VGLib.connectionService call. If this property
is not defined, the server name that is specified on the VGLib.connectionService 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.
- product
- Receives the database product name. The argument, if any, must be an item
of type CHAR and length 8.
To determine the string that will be received
when your code connects to a particular database, review the product documentation
for the database or driver; or run your code in a test environment and write
the received value to a file.
- release
- Receives the database release level. The argument, if any, must be an
item of type CHAR and length 8.
To determine the string that will be received
when your code connects to a particular database, review the product documentation
for the database or driver; or run your code in a test environment and write
the received value to a file.
- connectionOption
- Valid
values are as follows:
- D1E
- D1E is the default. The 1 in the option name
indicates that only a one-phase commit is supported,
and the E indicates that any disconnect must be explicit.
In this case, a commit or rollback has no effect on an existing connection.
A connection to a database does not close cursors,
release locks, or end an existing connection. If the run unit is already connected
to the same database, however, the effect is equivalent to specifying DISC
then D1E.
You can use multiple connections to
read from multiple databases, but you should update only one database in a
unit of work because only a one-phase commit is available.
- D1A
-
The
1 in the option name indicates that
only a
one-phase commit is supported, and the
A indicates
that any disconnect is
automatic. Characteristics
of this option are as follows:
- You can connect to only one database at a time
- A commit, rollback, or connection to a database ends an existing connection
- DISC
- Disconnect from the specified database. Disconnecting from a database
causes a rollback and releases locks, but only for that database.
- DCURRENT
- Disconnect from the currently connected database. Disconnecting from a
database causes a rollback and releases locks, but only for that database.
- DALL
- Disconnect from all connected databases. Disconnecting from all databases
causes a rollback in those database, but not in other recoverable resources.
- SET
- Set a connection current. (By default, the connection most recently made
in the run unit is current.)
The following values are supported for compatibility
with VisualAge Generator,
but are equivalent to D1E: R, D1C, D2A, D2C, D2E.