Start syntax for the Db2 command line processor
You start the Db2 command line processor by running the Java™ program com.ibm.db2.clp.db2 from z/OS UNIX System Services.
- java com.ibm.db2.clp.db2
- Starts the Db2 command line processor.
To simplify starting the Db2 command line processor, you can define an alias for this command, and then start the command line process by specifying the alias. For example:
alias db2="java com.ibm.db2.clp.db2" db2
- -Ddb2.jcc.propertiesFile=java-properties-file
- The Db2 command line processor runs under the
IBM Data Server Driver for JDBC and
SQLJ.
-Ddb2.jcc.propertiesFile=java-properties-file
specifies the name of a file that contains configuration properties for the IBM Data Server Driver for JDBC and SQLJ. Specify this option only if your system administrator tells you to do so. - -Dfile.encoding=file-encoding
- Specifies the file encoding that is used for a Db2 command line processor input file. For example, if the data in the input file has UTF-8 encoding, specify
-Dfile.encoding=UTF-8
. - option-flags
- Specifies one or more options for the Db2 command line processor. When you specify more than one option,
separate the option flags with spaces. To turn an option on, precede the option flag with a minus
(-) sign. To turn the option off, precede the option flag with a plus (+) sign.
The following table lists the options and their default values, if the defaults have not been set in a Db2 command line processor properties file.
Table 1. Command line processor option flags Option flag Option description Default setting a
Display the contents of the SQLCA after SQL statement execution. OFF c
Automatically commit SQL statements. ON f file-name
Read command input from the file specified by file-name. OFF o
Display data and messages on the standard output device. ON s
Stop the Db2 command line processor and exit to the operating system if an error occurs during execution of a statement or command. OFF t
Use the semicolon (;) as the statement termination character. If this option is not set, the command line processor handles each line as a complete statement unless the line ends with a space followed by a backslash( \). OFF tdx
Use x as the statement termination character. OFF u user-id/credential
Use the specified values when making a connection from the file specified in option flag f. - user-id
- The user ID for the connection.
- credential
- The password or RACF PassTicket for the connection
OFF v
Echo the command text to the standard output device. OFF x
Return data without any headers. OFF z file-name
Store output data and messages in the file specified by file-name. OFF The values of any options that you do not specify are determined by the values in the properties file that is specified by the CLPPROPERTIESFILE environment variable.
Examples
- Example: Starting the Db2 command line processor with defaults
- Suppose that no alias has been set for the Db2 command line processor name. Use this command to start the command
line processor with the default values:
java com.ibm.db2.clp.db2
- Example: Starting the Db2 command line processor with options
- Suppose that the alias
db2
has been set for the Db2 command line processorname. You want to start the command line processor with these options, which are not the default options:- After each SQL statement is executed, the contents of the SQLCA are displayed.
- COMMIT is not executed automatically after each SQL statement.
- The statement termination character is that pound sign (#).
db2 -a +c -td#
- Example: Starting the Db2 command line processor in batch mode
- Suppose that the alias
db2
has been set for the Db2 command line processor name. You want to run the command line processor with these options:- The Db2 command line processor runs in batch mode. The db2commands.clp file contains the commands.
- The commands are echoed to the display.
Use this command:
db2 -f db2commands.clp -v
- Example: Specifying a user ID and password or RACF PassTicket to run an SQL file
- Suppose 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