Start of change

CONNECT (Db2 command line processor)

The CONNECT command establishes a connection to a Db2 server.

Read syntax diagramSkip visual syntax diagram CONNECT TO connection-urlUSERuser-idUSINGpasswordconnection-alias
connection-url
Read syntax diagramSkip visual syntax diagram server : port / database :connection-properties
connection-properties
Read syntax diagramSkip visual syntax diagram property= value;
TO connection-url
Specifies the Db2 database system to which the connection is made. It consists of the following parts:
server
The domain name or IP address of the Db2 database system.
port
The TCP/IP server port number that is assigned to the Db2 database system. This is an integer in the range 0–65535. The default is 446.
database
A name for the Db2 database system. database is the Db2 location name that is defined during installation. All characters in the Db2 location name must be uppercase characters.
You can determine the location name by executing the following SQL statement on the Db2 database system to which you want to connect:
SELECT CURRENT SERVER FROM SYSIBM.SYSDUMMY1;
connection-properties
A list of IBM Data Server Driver for JDBC and SQLJ properties and their values. You can specify one or more property and value pairs. Each property and value pair, including the last one, must end with a semicolon (;). Do not include spaces or other white space characters anywhere within the list of property and value strings.

Specify connection properties only if your system administrator tells you to do so.

USER user-id
The authorization name to use when connecting to the Db2 server.

This name is case insensitive. However, if you run the LIST TABLES command to see your own tables, the case of user-id must match the case of the schema name for your tables. For example, if you connect to the Db2 database server with a user ID of myid, LIST TABLES does not list tables with a schema name of MYID.

USING password
The password for the authorization name that is used when connecting to the Db2 server.
connection-alias
A name that corresponds to an entry in the properties file that is defined by the CLPPROPERTIESFILE environment variable. That entry specifies the connection URL, user ID, and password for the connection.
Example: Making a connection for the command line processor by specifying a connection URL, ID and password
Suppose that your system administrator told you that the Db2 server against which you want to use the command line processor has the connection URL syszos1.abc.com:5021/ABCLOC1. Your ID is myid01 and your password is mypw01. Use this command to make a connection to that server:
CONNECT TO syszos1.abc.com:5021/ABCLOC1 USER myid01 USING mypw01
Example: Making a connection for the command line processor by specifying a connection alias
Suppose that the CLPPROPERTIESFILE environment variable specifies a file named clp.properties. In that file, the following connection alias is defined:
MYALIAS01=syszos1.abc.com:5021/ABCLOC1,myid01,mypw01
Use this command to make a connection using the connection alias:
CONNECT TO MYALIAS01
Start of changeExample: Specifying a user ID and password or RACF PassTicket to run an SQL fileEnd of change
Start of changeSuppose that you want to use the Db2 command line processor to connect to a server and your system administrator provides the following connection URL for the server: syszos1.abc.com:5021/ABCLOC1

You can create a file named script.sql that contains the following statement:

CONNECT TO syszos1.abc.com:5021/ABCLOC1

Also suppose that the alias db2 has been set for the Db2 command line processor name, and your user ID is myid01. If your password is mypw01, you can use the following command to connect to the server:

db2 -f script.sql -u myid01/mypw01

If your credential is the RACF PassTicket phrase TMOK73SJ, you can use the following command to connect to the server:

db2 -f script.sql -u myid01/TMOK73SJ
End of change
End of change