DB2 Examples
Comprehensive examples for exporting data from IBM DB2 using the generic odbc connection type.
DB2 ODBC Driver
DB2 is not a native connection type, so FastBCP connects to it through ODBC. Install the IBM DB2 ODBC driver, then provide either a DSN (--dsn) or a full connection string (--sourceconnectstring) as shown below.
Connection String
Single-threaded export:
.\FastBCP.exe `
--connectiontype "odbc" `
--sourceconnectstring "Driver={IBM DB2 ODBC DRIVER};Database=SAMPLE;Hostname=db2server.company.corp;Port=25010;Protocol=TCPIP;Uid=db2user;Pwd=password;CurrentSchema=DB2ADMIN" `
--query "SELECT * FROM DB2ADMIN.ORDERS" `
--directory "C:\temp" `
--fileoutput "db2_orders.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "None"
Parallel export with Ntile method:
.\FastBCP.exe `
--connectiontype "odbc" `
--sourceconnectstring "Driver={IBM DB2 ODBC DRIVER};Database=SAMPLE;Hostname=db2server.company.corp;Port=25010;Protocol=TCPIP;Uid=db2user;Pwd=password;CurrentSchema=DB2ADMIN" `
--query "SELECT * FROM DB2ADMIN.ORDERS" `
--directory "C:\temp" `
--fileoutput "db2_orders.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Ntile" `
--distributekeycolumn "ORDER_ID" `
--paralleldegree -2 `
--merge "False"
Parallel export with Random method:
.\FastBCP.exe `
--connectiontype "odbc" `
--sourceconnectstring "Driver={IBM DB2 ODBC DRIVER};Database=SAMPLE;Hostname=db2server.company.corp;Port=25010;Protocol=TCPIP;Uid=db2user;Pwd=password;CurrentSchema=DB2ADMIN" `
--query "SELECT * FROM DB2ADMIN.ORDERS" `
--directory "C:\temp" `
--fileoutput "db2_orders.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "Random" `
--distributekeycolumn "ORDER_ID" `
--paralleldegree 8 `
--merge "False"
DSN Connection
If a DSN is already configured on the machine, you can use --dsn instead of --sourceconnectstring.
.\FastBCP.exe `
--connectiontype "odbc" `
--dsn "DB2_DSN" `
--query "SELECT * FROM DB2ADMIN.ORDERS" `
--directory "C:\temp" `
--fileoutput "db2_orders.csv" `
--decimalseparator "." `
--delimiter "|" `
--dateformat "yyyy-MM-dd HH:mm:ss" `
--encoding "UTF-8" `
--parallelmethod "None"
Quoting special identifiers
If your DB2 schema or table name contains special characters (e.g. HCR_BI."APER@XPSAHISTO"), keep the double quotes around the identifier inside your --query value so DB2 treats it as a delimited identifier.
tip
Build your command with the Wizard