DB2 Version 10.1 for Linux, UNIX, and Windows

db2cli - DB2 interactive CLI command

Starts the interactive call level interface (CLI) environment for design and prototyping in CLI.

Authorization

The db2cli command is located in the bin subdirectory of the directory where you installed this driver. On UNIX operating systems, for the IBM® Data Server Client, this command is located in the home_dir/sqllib/bin directory, where home_dir is the home directory of the instance owner. On Windows operating systems, the command is located in the DB2PATH\bin directory, where DB2PATH is the installation location of the DB2® copy.

None

Required connection

None

Command syntax

Read syntax diagramSkip visual syntax diagram
>>-db2cli--+------------------------------------------------+--><
           +-validate--+----------------------+-------------+   
           |           +-| Validate options |-+             |   
           |           '- -help---------------'             |   
           +-bind--+-filename--| Bind options |-+-----------+   
           |       '- -help---------------------'           |   
           +-registerdsn--| Register DSN options |----------+   
           +-csc-- -info------------------------------------+   
           +-| Execsql options |----------------------------+   
           +-install--| Install options |-------------------+   
           +-writecfg--| Write configuration file options |-+   
           '- -help-----------------------------------------'   

Validate options

|--+- -dsn--dsn_name------------------+------------------------->
   '- -database--database:server:port-'   

>--+--------------------------------------------------------------------------+-->
   +- -connect--+------------------------------------------+------------------+   
   |            '- -user--username--+--------------------+-'                  |   
   |                                '- -passwd--password-'                    |   
   '- -connect--+------------------+-- --keystoredbpassword--keystoredbpasswd-'   
                '- -user--username-'                                              

>--+------------------+-----------------------------------------|
   '- -f--output_file-'   

Register DSN options

                                                                          .- -user---.     
|--+-+- -add--+-+-------+--dsn_name-+----------------------------------+--+----------+-+--|
   | |        | '- -dsn-'           |                                  |  '- -system-' |   
   | |        '- -alldsn------------'                                  |               |   
   | +- -remove--+--------------------------+--+-+-------+--dsn_name-+-+               |   
   | |           +- -copyname--copy_name----+  | '- -dsn-'           | |               |   
   | |           '- -allcopies--+---------+-'  '- -alldsn------------' |               |   
   | |                          '- -force-'                            |               |   
   | '- -list--+-----------------------+-------------------------------'               |   
   |           +- -copyname--copy_name-+                                               |   
   |           '- -allcopies-----------'                                               |   
   '- -help----------------------------------------------------------------------------'   

Execsql options

                .- -execute-----.   
|----execsql----+---------------+------------------------------->
                '- -prepareonly-'   

>--+-| Server options |---+-- -inputsql--sqlfile---------------->
   '- -connstring--string-'                        

>--+------------------------+----------------------------------->
   '- -outfile--output_file-'   

>--+---------------------------------+-------------------------->
   '- -statementdelimiter--delimiter-'   

>--+-----------------------------------+--+--------+------------|
   '- -commentstart--comment_indicator-'  '- -help-'   

Server options

|-- -dsn--dsn_name--+----------------------------+--------------|
                    '-| Authentication options |-'   

Authentication options

|-- -user--username--+------------------+-----------------------|
                     '- -passwd--passwd-'   

Install options (available only on Windows)

|--+-+- -setup--+--------------------------+-+-+----------------|
   | |          '- -appdatapath--path_name-' | |   
   | '- -cleanup--+---------+----------------' |   
   |              '- -force-'                  |   
   '- -help------------------------------------'   

Write configuration file options

|--+-add--+-+- -dsn--dsn_name------------------------------------------+--+----------------------------------------------------------------+-+-+--|
   |      | '- -database--db_name-- -host--host_name-- -port--p_number-'  |                      .-;----------------------------------.    | | |   
   |      |                                                               |                      V                                    |    | | |   
   |      |                                                               '-+- -parameter--+--"----parameter_name--=--parameter_value-+--"-' | |   
   |      |                                                                 '- -parameters-'                                                 | |   
   |      |                      .-;----------------------------------.                                                                      | |   
   |      |                      V                                    |                                                                      | |   
   |      '-+- -parameter--+--"----parameter_name--=--parameter_value-+--"-------------------------------------------------------------------' |   
   |        '- -parameters-'                                                                                                                   |   
   +-remove--+-+- -dsn--dsn_name------------------------------------------+--+--------------------------------------------+-+------------------+   
   |         | '- -database--db_name-- -host--host_name-- -port--p_number-'  |                      .-;--------------.    | |                  |   
   |         |                                                               |                      V                |    | |                  |   
   |         |                                                               '-+- -parameter--+--"----parameter_name-+--"-' |                  |   
   |         |                                                                 '- -parameters-'                             |                  |   
   |         |                      .-;--------------.                                                                      |                  |   
   |         |                      V                |                                                                      |                  |   
   |         '-+- -parameter--+--"----parameter_name-+--"-------------------------------------------------------------------'                  |   
   |           '- -parameters-'                                                                                                                |   
   '- -help------------------------------------------------------------------------------------------------------------------------------------'   

Bind options

|--+- -dsn--dsn_name------------------+------------------------->
   '- -database--database:server:port-'   

>--+------------------------------------------+----------------->
   '- -user--username--+--------------------+-'   
                       '- -passwd--password-'     

>--+-----------------------------------+------------------------|
   '- -options--"various_bind_options"-'   

Command parameters

validate

Validates and tests the CLI environment configuration. This option shows a list of keywords that are found in the db2cli.ini and db2dsdriver.cfg files. If any keywords are invalid for the specified data source or database name, they are listed as UNKNOWN. IBM data server clients (the IBM Data Server Client or the IBM Data Server Runtime Client), the db2cli validate command lists the installed DB2 client packages on a Windows operating system. When you issue the db2cli validate command from the IBM data server clients, the list is limited to the IBM data server clients that are installed on the Windows operating system. To list IBM Data Server Driver for ODBC and CLI packages and the IBM data server client packages that are installed on a Windows operating system, you must issue the db2cli validate command from the IBM Data Server Driver for ODBC and CLI installation. The list indicates the current copy name as [C] and the default copy name as [D].

-dsn dsn_name
Start of changeSpecifies the data source name (DSN) to validate. If dsn_name has white space in the middle, surround it with double quotation marks.End of change
-database database:server:port
Specifies the database name, server name, and port number to validate. You must use a colon to separate the database name, server name, and port number. The server name must consist of a fully qualified domain name (FQDN), for example, TESTDB:dbserver.example.com:19677.
-connect
Specifies the DSN or database to which the db2cli validate command connects and writes information about the connection attempt to the command output.
-user username
Specifies the user name to use for the connection.
-passwd password
Specifies the password to use for the connection.
-keystoredbpassword keystoredbpasswd
Specifies the password for the SSL connection when the Authentication parameter is set to CERTIFICATE.
Restriction: If a connection is made to a gateway that is at a lower version than the client version, new features that are supported with a corresponding client-server combination might not be available.
-f OUTPUT_FILE
Specifies an optional output file for the results of the db2cli command.
-help
Shows the help information that is related to the usage of the validate parameter.
registerdsn

Specifies the db2cli register DSN mode. Use this command parameter to register a DSN in the Windows operating system.

-add dsn_name|-alldsn
Adds system or user ODBC data sources to the Microsoft ODBC Data Source Administrator.
dsn_name
Start of changeIndicates the DSN to register. The value of dsn_name must be the DSN that is defined in the db2cli.ini file or Start of changethe dsn alias defined inEnd of changedb2dsdriver.cfg file and cannot be a DBALIAS name. The -add dsn-name parameter adds data sources for cataloged databases that are available in the local database directory. The dsn-name can indicate a data source that is defined in the db2cli.ini or Start of changethe dsn alias defined inEnd of changedb2dsdriver.cfg file, and a database alias in the local database directory in IBM Data Server clients. If the dsn_name has white space in the middle, surround it with double quotation marks.End of change
-dsn
Start of changeEnables the user to specify a DSN name that needs to be added to the Microsoft ODBC Data Source Administrator. The db2cli registerdsn -add -dsn command is available in DB2 Version 10 Fix Pack 1 and later on Windows platform.End of change
-alldsn
Registers all the data sources that are defined in the db2cli.ini file and Start of changethe dsn aliases defined in theEnd of changedb2dsdriver.cfg file. You must use this parameter with the -add parameter.

The registerdsn -add-alldsn parameter continues to search for data sources that are available only in the db2cli.ini and db2dsdriver.cfg files and does not add data sources for cataloged databases.

-user
Registers data sources as user ODBC data sources. If no parameter is specified, data sources are registered as user ODBC data sources.
-system
Registers data sources as system ODBC data sources.
-remove dsn_name
Start of changeRemoves a system or user ODBC data source from the Microsoft ODBC Data Source Administrator. If the dsn_name has white space in the middle, surround it with double quotation marks.
-alldsn
Removes all the user or system ODBC data source entries of a specified DB2 copy from the Microsoft ODBC Data Source Administrator. The db2cli register -remove -alldsn command is available in DB2 Version 10 Fix Pack 1 and later fix packs on Windows operating systems.
-copyname copy_name
Removes the user or system ODBC data source entries of a specified DB2 copy from the Microsoft ODBC Data Source Administrator. If you do not specify a copy name, the current copy name is used. The current copy name is the copy name of the client where the db2cli utility is from. If you specify the -copyname option with the -alldsn option, all data source entries in the Microsoft ODBC Data Source Administrator are removed from the specified DB2 copy. The db2cli register -remove -copyname command is available in DB2 Version 10 Fix Pack 1 and later fix packs on Windows operating systems.
-allcopies
Removes all the user or system ODBC data source entries of all the DB2 copies from the Microsoft ODBC Data Source Administrator. Unless you also specify the -force option, you are prompted to confirm that you want to remove all ODBC data source entries. The db2cli register -remove -allcopies command is available in DB2 Version 10 Fix Pack 1 and later fix packs on Windows operating systems.
-force
Removes all the user or system ODBC data source entries without prompting you for confirmation. You can use the -force option only with the -allcopies option. The db2cli register -remove -allcopies -force command is available in DB2 Version 10 Fix Pack 1 and later fix packs on Windows operating systems.
-dsn
Specifies a DSN name to remove from the Microsoft ODBC Data Source Administrator. The db2cli register -remove -dsn command is available in DB2 Version 10 Fix Pack 1 and later fix packs on Windows operating systems. The default option is -user, which removes a user DSN. You must specify the -system option to remove a system DSN.
End of change
-list
Lists all the system or user IBM Data Server ODBC data sources that are registered in the Microsoft ODBC Data Source Administrator.
-copyname copy_name
Lists the user or system ODBC data source entries of the specified DB2 copy in the Microsoft ODBC Data Source Administrator. If you do not specify the copy name, the current copy name is used. The current copy name is the copy name of the client where the db2cli utility is from. The db2cli register -list -copyname command is available in DB2 Version 10 Fix Pack 1and later fix packs on Windows operating systems.
-allcopies
Lists all the user or system ODBC data source entries of all the DB2 copies in the Microsoft ODBC Data Source Administrator. The db2cli register -list -allcopies command is available in DB2 Version 10 Fix Pack 1 and later fix packs on Windows operating systems.
-help
Shows the help information that is related to the usage of the registerdsn parameter.
Note: To add, remove, or list 32-bit ODBC data source entries on 64-bit Windows machines, use db2cli32 command.
csc -info
Displays connection supervisor client (CSC) information. A CSC is a dynamically loadable library that CLI uses for the purpose of end-to-end monitoring.
-execsql

Executes or prepares the SQL statements specified in an input file. Can also save output to a file.

-execute
Specifies that the SQL statements in the SQL script file are prepared and run. This is the default if no parameter is specified. Results are displayed in the console. To save the output to a file, specify the option -output with the absolute or relative path of the file. SQL statements in the SQL script file cannot have parameter markers.
-prepareonly
Specifies that the SQL statements in the file specified by the -inputSql option are prepared but not run. Use this option to check the syntax of the SQL statements without running the statements.
-commentstart comment_indicator
Specifies the character combination that appear at the beginning of a line to indicate a comment line. The default value of comment_indicator is two dashes (--). If a comment spans multiple lines, start each line with the comment_indicator character combination. The maximum length of a comment line is 128 characters. In the input SQL file, the text after the comment characters can contain statement cursor attributes. The cursor attributes apply to the SQL statement immediately following the comment.
-connstring string
Specifies the database name, server, and port number of the target database. The information must be specified in the format as defined by the InConnectionString argument in the SQLDriverConnect API function. For example, DATABASE=SAMPLE;HOSTNAME=test.ibm.com;PORT=50000;UID=db2user;PWD=db2pwd.
-dsn dsn_name
Start of changeSpecifies the data source name Start of changein the db2cli.ini file or the dsn alias defined in db2dsdriver.cfg file.End of change. If the dsn_name has white space in the middle, surround it with double quotation marks.End of change
-help
Displays summary usage information.
-inputsql sqlfile
Specifies the input file that contains SQL statements. The value of sqlfile is the absolute or relative path of the file. The SQL statements in the file are separated by a delimiter. Only preparable statements are used. DB2 commands such as DESCRIBE TABLE and BIND are not allowed.

Only SQL statements and comments can be in the input SQL file. The file cannot contain CLI specific attributes or keywords. Batch SQL statements are not supported.

-outfile outputfile
Specifies the absolute or relative path of the file to store the output results. When this option is not specified, the results are displayed in the console.
-passwd password
Specifies the password to use for authenticating with the database.
-statementdelimiter delimiter
Specifies the character combination that is used in the input SQL file to separate statements. The default value of delimiter is a carriage return.
-user username
Specifies the user for authenticating with the database.
install

Registers or unregisters the IBM Data Server Driver for ODBC and CLI in the Windows registry.

-setup
Start of change Registers the IBM Data Server Driver for ODBC and CLI under ODBC in the Windows registry. This parameter also creates configuration folders (cfg, cfgcache, db2dump) and sample configuration file in the default application data path.End of change
Start of change-appdatapath <path name>End of change
Creates configuration folders (cfg, cfgcache, db2dump) and sample configuration files in the path name.
-cleanup
Unregisters the current IBM Data Server Driver for ODBC and CLI from the Windows registry under ODBC. The cleanup then removes the folders, configuration sample files, and license management files that are created at the application data path for the current installation. Any user-created files or folders are not removed unless you specify the –force option.
-force
When specified with the –cleanup option, the entire install-specific folder is removed from the application data path. This folder belongs to this installation only. Any user-created files or folders in this folder are removed without any prompt or warning.
-help
Shows the help information that is related to the usage of the install parameter.
writecfg add|remove
Updates the db2dsdriver.cfg configuration file.
add -dsn| -database | -paramter[s]
Adds information about data sources, databases, or parameters to the db2dsdriver.cfg configuration file.
-dsn dsn_name
Start of changeSpecifies the DSN for which you want to add or update the parameter elements, the session global variable parameter element, or the entire <dsn> subsection in the configuration file. If the dsn_name has white space in the middle, surround it with double quotation marks.

If there is no existing <dsn> subsection with the dsn_nameStart of changeas dsn aliasEnd of change in the configuration file, a new <dsn> subsection in the <dsncollection> section is added.

If there is a dsn subsection with the dsn_nameStart of changeas dsn aliasEnd of change in the configuration file, new parameters or session global variables information provided is appended to the existing <dsn> subsection.

End of change
-parameter[s] "par1=par1_val[;...;parN=parN_val]"
Specifies the parameter information to add or update parameter elements in the specified <dsn> subsection of the db2dsdriver.cfg configuration file.

If you specify a new parameter element that is not found in the <dsn> subsection of the db2dsdriver.cfg configuration file, a new parameter element is added to the <dsn> subsection.

If the specified parameter element is already present in the configuration file, the existing parameter value in the <dsn> subsection is updated with the value that you specify with the -parameter[s] option.

Special characters, such as path separators in the value, must be preceded by the escape character "\".

The db2cli writecfg command does not verify the syntax or validate the value of the specified parameter.

-database db_name -host host_name -port port_number
Specifies the connection information for a <database> subsection. This information consists of the database name, the host name where the database is located, and the port number of the database server.

If a <database> subsection with the same db_name information exists in the db2dsdriver.cfg configuration file, the specified parameter element is appended to the <database> subsection. Otherwise, the specified parameter elements or the session global variable parameter elements are added to a new <database> subsection.

-parameter[s] "parameter_name1=par1_val[;...;parN=parN_val]"
Specifies the parameter information to add or update a parameter element for the specified database name in the db2dsdriver.cfg configuration file.

If you specify a new parameter element that is not found in the <database> subsection of the db2dsdriver.cfg configuration file, a new parameter element is added to the <database> subsection.

If the specified parameter element is already present in the configuration file, the existing parameter value in the <database> subsection is updated with the value that you specify with the -parameter[s] option.

Special characters, such as path separators in the value, must be preceded by the escape character "\".

The db2cli writecfg command does not verify the syntax or validate the value of the specified parameter.

-parameter[s] "parameter_name1=par1_val[;...;parN=parN_val]"
Specifies the parameter information to add or update a parameter element for all databases and DSNs in the db2dsdriver.cfg configuration file.

To add a parameter to the global <parameters> section, specify the parameter information without indicating a database or a data source.

If you specify a new parameter element that is not found in the <parameters> subsection of the db2dsdriver.cfg configuration file, a new parameter element is added to the <parameters> subsection.

If the specified parameter element is already present in the configuration file, the existing parameter value in the <parameters> subsection is updated with the value that you specify with the -parameter[s] option.

Special characters, such as path separators in the value, must be preceded by the escape character "\".

The db2cli writecfg command does not verify the syntax or validate the value of the specified parameter.

remove -dsn| -database | -paramter[s]
Removes information about data sources, databases, or parameters from the db2dsdriver.cfg configuration file.
-dsn dsn_name
Start of changeSpecifies the DSN for which you want to remove the parameter information or the entire data source section in the configuration file. If the dsn_name has white space in the middle, surround it with double quotation marks.

To remove parameter information, specify the corresponding DSN and the parameter information.

To remove the entire data source section, specify only the DSN without any parameter information.

End of change
-parameter[s] "parameter_name1[;...;parameter_nameN]"
Specifies the parameter information to remove from the specified DSN in the db2dsdriver.cfg configuration file.

If the indicated parameter is not in the specified <dsn> subsection of the configuration file, no action is taken.

-database db_name -host host_name -port port_number
Specifies the connection information for a database for which you want to remove the parameter information or the entire database section in the configuration file.

To remove parameter information, specify the database connection information for the corresponding database section and the parameter information.

To remove the entire database section, specify only the database connection information without any parameter information.

-parameter[s] "parameter_name1[;...;parameter_nameN]"
Specifies the parameter information to remove from the specified database name in the db2dsdriver.cfg configuration file.

If the indicated parameter is not in the <database> subsection of the configuration file, no action is taken.

-parameter[s] "par1[;par2;...;parN]"
Specifies the parameter information that is to be removed from the specified database or data source in the db2dsdriver.cfg configuration file.

If the indicated parameter is not in the specified database or data source section of the configuration file, no action is taken.

Special characters, such as path separators in the value string, must be preceded by the character "\".

-help
Shows the help information that is related to the usage of the writecfg parameter.
bind

Binds the specified filename against the target database. The db2cli bind command first connects to the target database with the information provided in the db2cli bind command parameters then performs the bind action. Bind files have the extension .bnd.

filename
The filename can be a name of bind file or list file that contains the name of several bind files. If a list file is specified, the @ character must be prefixed to the list file name. The fully qualified bind file name can be specified within a double quotation mark.
-dsn dsn_name
Specifies the data source name (DSN) you bind to. When using this bind option, all information except for a valid user ID and password required to connect to the target database must be present in:
  • The data source name section in the db2cli.ini file.
  • The database section or the DSN section in the db2dsdriver.cfg file.
  • The local catalog entry.
-database database:server:port
Specifies the database name, server name, and port number you bind to. You must use a colon to separate the database name, server name, and port number. The server name must consist of a fully qualified domain name (FQDN), for example, TESTDB:dbserver.example.com:19677.
-user username
Specifies the user name to use for the connection.
-passwd password
Specifies the password to use for the connection.
-options "various_bind_options"
Specifies the bind options and their values. Available bind options are:
  • BLOCKING
  • COLLECTION
  • ENCODING
  • GENERIC
  • ISOLATION
  • KEEPDYNAMIC
  • REOPT
-help
Shows the help information that is related to the usage of the bind parameter.
Note: The bind option for the db2cli command is available in Version 10.1 Fix Pack 2 and later fix packs.
-help
Shows the db2cli command help information.

Usage notes

The interactive CLI interface consists of a set of commands that you can use to design, prototype, and test CLI function calls. It is a testing tool that is provided for the convenience of those programmers who want to use it, and IBM makes no guarantees about its performance. This interface is not intended for users, and so does not have extensive error-checking capabilities.

Three types of commands are supported:
CLI commands
Commands that correspond to (and have the same name as) each of the function calls that is supported by CLI.
Support commands
Commands that do not have an equivalent CLI function.
Additional modes
You can use the additional modes for the db2cli command to validate and test the CLI environment configuration.

You can issue commands interactively or from within a file. Similarly, you can display the command output on the terminal or write it to a file. A useful feature of the IBM Data Server Driver for ODBC and CLI is the ability to capture all of the commands that are entered during a session, and to write them to a file, thus creating a command script that you can rerun at a later time.

For IBM Data Server client packages on Windows 64-bit operating systems, the 32-bit version of db2cli (db2cli32.exe) is supported in addition to the 64-bit version of the db2cli command.

SQL statements are executed by using the SQLExecDirect() function. When executing SQL statements, the db2cli execsql command uses the database settings specified in the db2cli.ini and db2dsdriver.cfg files.

Error messages returned by the db2cli command are formatted using the same format as the SQLGetDiagRec() function.

Start of changeCommand line ODBC Registration: To configure and register DSN for Windows:
  1. Catalog the server node. For more information, see "Cataloging a TCP/IP node from a client using the CLP".
  2. Catalog the database that you want to connect to. For more information, see "Cataloging a database from a client by using the CLP".
  3. (Optional) Catalog the Database Connection Services (DCS) directory. For more information, see "Catalog DCS database command".
  4. Register the DSN by using the db2cli interactive tool.
    • For 32-bit ODBC DSN, use the db2cli32 command.
    • For 64-bit ODBC DSN, use the db2cli command.
For 64-bit installations, both the db2cli and db2cli32 versions can be used to register the DSN. The db2cli command registers a 64-bit DSN and the db2cli32 command registers a 32-bit DSN.End of change

Start of changeFor 32-bit installations, the db2cli command by default registers only 32-bit DSN.End of change

Start of changeThe DSN to be registered must be in the db2cli.ini or the db2dsdriver.cfg file.End of change

Examples

db2cli validate
In the following example, the utility reads the [COMMON] section of db2cli.ini file, the [DSN] section for the sample DSN name in the db2cli.ini file, and the <dsn> element for the sample DSN name in the db2dsdriver.cfg file. Both valid and invalid keywords are displayed; invalid keywords are listed as UNKNOWN.
db2cli validate –dsn sample
In the next example, the utility reads the [COMMON] section of db2cli.ini file, the <database> section for the database dbname1, the server server1.net1.com, and port 50001, in the db2dsdriver.cfg file. Both valid and invalid keywords are displayed; invalid keywords are listed as UNKNOWN.
db2cli validate -database dbname1:server1.net1.com:50001
Start of changeIn the next example, the utility is used with a data source name. The data source name is applied with double quotation marks ("").
db2cli validate -dsn "IBM - User Acceptance" -connect -user <userid> -passwd <password>
End of change
db2cli writecfg
For the examples that are described in this section, assume that the db2dsdriver.cfg file has the following content:
<configuration>
  <dsncollection>
   <dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"> 
    <parameter name="DisableAutoCommit" value="TRUE"/>
   </dsn>
  </dsncollection>
  <databases>
   <database name="name1" host="server1.net1.com" port="50001">
    <parameter name="CurrentSchema" value="OWNER1"/>
   </database> 
  </databases>
  <parameters>
     <parameter name="IsolationLevel" value="SQL_TXN_READ_COMMITTED"/>
  </parameters>
</configuration>
The following example adds a new data source element to the db2dsdriver.cfg configuration file:
$db2cli writecfg add –dsn alias2 –database name2 -host server1.net1.com -port 50001
As a result of this command, the dsncollection section is modified as follows:
<dsncollection>
 <dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"> 
  <parameter name="DisableAutoCommit" value="TRUE"/>
 </dsn>
 <dsn alias="alias2" name="name2" host="server1.net1.com" port="50001"/>
</dsncollection>
The following example adds parameter information to an existing data source in the configuration file:
db2cli writecfg add –dsn alias2 –parameters “DisableAutoCommit=FALSE;CurrentSchema=OWNER2;pureQueryXml=C:\\clico”
As a result of this command, the dsncollection section is modified as follows:
<dsncollection>
 <dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"> 
  <parameter name="DisableAutoCommit" value="TRUE"/>
 </dsn>
 <dsn alias="alias2" name="name2" host="server1.net1.com" port="50001">
  <parameter name="DisableAutoCommit" value="FALSE"/>
  <parameter name="CurrentSchema" value="OWNER2"/>
..<parameter name="pureQueryXml" value="C:\clico"/>
 </dsn>
</dsncollection>
The following example adds a new database element with parameters in the configuration file:
db2cli writecfg add –database name2 –host server1.net1.com -port 50001  -parameters “LockTimeout=20;KeepAliveTimeout=20000”
As a result of this command, the databases section is modified as follows:
<databases>
 <database name="name1" host="server1.net1.com" port="50001">
  <parameter name="CurrentSchema" value="OWNER1"/>
 </database> 
 <database name="name2" host="server1.net1.com" port="50001">
  parameter name=" LockTimeout" value="20"/>
  parameter name="KeepAliveTimeout" value="20000"/>
 </database> 
</databases>
The following example modifies an existing parameter for an existing dsn element in the configuration file:
db2cli writecfg add –dsn alias1 –parameter “DisableAutoCommit=FALSE”
As a result of this command, the dsncollection section is modified as follows:
<dsncollection>
 <dsn alias="alias1" name="name1" host="server1.net1.com" port="50001"> 
  <parameter name="DisableAutoCommit" value="FALSE"/>
 </dsn>
 <dsn alias="alias2" name="name2" host="server1.net1.com" port="50001">
  <parameter name="DisableAutoCommit" value="FALSE"/>
  <parameter name="CurrentSchema" value="OWNER2"/>
..<parameter name="pureQueryXml" value="C:\clico"/>
 </dsn>
</dsncollection>
The following example adds a parameter element to the global section in the configuration file:Start of change
db2cli writecfg add -parameter "ReceiveTimeout=20000"
End of change As a result of this command, the global section is modified as follows:
<parameters>
 <parameter name="IsolationLevel" value=" SQL_TXN_READ_COMMITTED"/>
 Start of change<parameter name="ReceiveTimeout" value="20000"/>End of change 
</parameters>
The following example removes a parameter element from a database in the configuration file:
db2cli writecfg remove –database name1 -host server1.net1.com -port 50001 –parameter “CurrentSchema”
As a result of this command, the databases section is modified as follows:
<databases>
 <database name="name1" host="server1.net1.com" port="50001">
 </database>
 <database name="name2" host="server1.net1.com" port="50001">
  parameter name="LockTimeout" value="20"/>
  parameter name="KeepAliveTimeout" value="20000"/>
 </database>
 </databases>
The following example removes a dsn element in the configuration file:
db2cli writecfg remove –dsn alias1
As a result of this command, the dsncollection section is modified as follows:
<dsncollection>
 <dsn alias="alias2" name="name2" host="server1.net1.com" port="50001">
  <parameter name="DisableAutoCommit" value="FALSE"/>
  <parameter name="CurrentSchema" value="OWNER2"/>
  <parameter name="pureQueryXml" value="C:\clico"/>
 </dsn>
</dsncollection>
db2cli execsql
In following example assume that the following table and procedures are created in the SAMPLE database:
create table employee(empid integer, empname varchar(100)

  CREATE PROCEDURE proc1 (  ) 
  DYNAMIC RESULT SETS 1 P1: 
  BEGIN
    DECLARE cursor1 CURSOR WITH RETURN FOR  SELECT * FROM fprem;  
    OPEN cursor1;
  END P1

  CREATE PROCEDURE PROC2(IN ID1 INTEGER,OUT NAME VARCHAR(20)) 
  BEGIN 
  DECLARE CUR1 CURSOR WITH RETURN TO CALLER FOR SELECT * FROM EMPLOYEE1 WHERE ID=ID1; 
    OPEN CUR1; 
  END
This example also assumes the SQL file test.sql contains the following text:
--Populate table( employee )
insert into employee(empid, empname) values(1, 'Adam')
insert into employee(empid, empname) values(2, 'Atul')
select empid, empname  from employee

--Execute the stored procedure
Call proc1( )
Enter the following db2cli command in a console window to run the SQL statements in the file:
db2cli execsql –dsn sample –inputsql test.sql
The following text is displayed in the console window:
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

insert into employee(empid, empname) values(1, 'Adam')
The SQL command completed successfully.

insert into employee(empid, empname) values(2, 'Atul')
The SQL command completed successfully.

select empid, empname  from employee

EMPID EMPNAME
1, Adam
2, Atul

Call proc1()

EMPID EMPNAME
1, Adam
2, Atul
Run a CALL statement for a stored procedure that has OUT arguments. The question mark (?) can be used as an OUT parameter.
The following example assumes that an SQL script file test2.sql contains the following text:
CALL PROC2( 1, ?)
Enter the following db2cli command in a console window to run the SQL statements in the file:
db2cli execsql –dsn sample –inputsql test2.sql 
The following text is displayed in the console window:
Value of output parameters
--------------------------
Parameter Name  : NAME
Parameter Value : -

ID
-----------
    1

Specify the -prepareonly option to prepare the SQL statements without running them. The DDL statements that are needed for the SQL statements must be run before you run the db2cli execsql command with the -prepareonly option.

The following example assumes that the SQL file test3.sql contains the following text:
--populate table( employee )
insert into employee(empid, empname) values(1, 'Adam');
insert into employee(empid, empname) values(2, 'Atul');
select empid, empname  from employee;
Also, assume that the table EMPLOYEE was created in the database. Enter the following db2cli command in a console window to prepare the SQL statements in the file:
db2cli execsql –prepareonly –dsn sample –inputsql test3.sql
The following text is displayed in the console window:
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

insert into employee(empid, empname) values(1, 'Adam')
The SQL command prepared successfully.

insert into employee(empid, empname) values(2, 'Atul')
The SQL command prepared successfully.

select empid, empname  from employee
The SQL command prepared successfully.
If you place DDL statements that are required for DML statements in the same file, 
the DML statements that require the DDL statements fail. 
For example, assume that the following text is in the file test4.sql, 
and assume that and the EMPLOYEE table has not been created in the database:
--create and populate table( employee )
create table employee(empid integer, empname varchar(100));
insert into employee(empid, empname) values(1, 'Adam');
insert into employee(empid, empname) values(2, 'Atul');
select empid, empname  from employee;

-- try to create another table with the same name
create table employee(empid integer, empname varchar(100));
The CREATE TABLE statement must be run before the INSERT and SELECT statements can be run successfully.
Enter the following db2cli command in a console window to prepare the SQL statements in the file:
db2cli execsql –prepareonly –dsn sample –inputsql test4.sql
The following text is displayed in the console window:
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

create table employee(empid integer, empname varchar(100))
The SQL command prepared successfully.

insert into employee(empid, empname) values(1, 'Adam')
The SQL command failed. During SQL processing it returned:
[IBM][CLI Driver][DB2/6000] SQL0204N  "EMPLOYEE" is an undefined name.  SQLSTATE=42704

insert into employee(empid, empname) values(2, 'Atul')
The SQL command failed. During SQL processing it returned:
[IBM][CLI Driver][DB2/6000] SQL0204N  "EMPLOYEE" is an undefined name.  SQLSTATE=42704

select empid, empname  from employee
The SQL command failed. During SQL processing it returned:
[IBM][CLI Driver][DB2/6000] SQL0204N  "EMPLOYEE" is an undefined name.  SQLSTATE=42704

create table employee(empid integer, empname varchar(100))
The SQL command prepared successfully.
In this example, the two CREATE SQL statements prepared successfully, however the EMPLOYEE table was not created in the database. The INSERT and SELECT statements did not prepare successfully because the EMPLOYEE table was not in the database.
db2cli bind
The following example binds the db2cli.lst list file:
$ db2cli bind @db2cli.lst –database “mydb:test.torolab.ibm.com:446” –options “BLOCKING 
  unambig REOPT always ISOLATION RR”
LINE    MESSAGES FOR db2cli.lst
------  --------------------------------------------------------------
        SQL0061W  The binder is in progress.
        SQL0091N  Binding was ended with "0" errors and "0" warnings.