The shell script is used to export the DB2 database table to a file, and in another blog post, Java code calls the shell script and passes in the parameter implementation DB2 database table export to a file to invoke the script and pass in the parameters through Java code implementation.
1#!/usr/bin/Env SH2 3dbschema=$14dbuser=$25dbpassword=$36tablename=$47filepath=$58delimiter=$69exportlimit=$7Ten OneSqlerr="NO ERROR MSG" A - ############################################################ - #: Wlog String the ############################################################ - Wlog () { -Wlog_dt= 'Date "+%y/%m/%d-%h:%m:%s" ` - Echo "\n${wlog_dt} $" + } - + ############################################################ A #: DB2Connect db2connstring at ############################################################ - connDB2 () { -Wlog"====================connect to $1=======================" -Wlog"DB2 Connect to user $" -# # CONN=DB2 Connect to $1User $2Using $3>/dev/NULL - if(DB2 Connect to $1User $2Using $3>/dev/NULL ) in Then -Wlog"succeed Connect to $" to Else +Wlog"Failed Connect to $" -Exit-1 the fi * } $ Panax Notoginseng ############################################################ - #: Db2connectrelease db2connstring the ############################################################ + releaseDB2 () { ADB2 Connect reset >/dev/NULL the } + - ############################################################ $ #: Db2export $ ############################################################ - exportDB2 () { - connDB2 ${dbschema} ${dbuser} ${dbpassword} theSql="select * from ${tablename} ${exportlimit}" -Wlog"Export to ${filepath} of Del modified by codepage=1208 coldel| ${sql}:"WuyiDb2"Export to ${filepath} of Del modified by Nochardel codepage=1208 coldel| ${sql}" the } - Wu ############################################################ - #: Main About ############################################################ $ run () { - # connDB2 ${dbnode} ${dbuser} ${dbpassword} ${dbname} -# sql="Select Inter_no,op_time from Inter_log" - A# db2-x ${sql}| whileRead Inter_no op_time +# Do the#Echo "Result:${inter_no}->${op_time}" -# Done $ the Echo "Begin to export the data:" the exportDB2 the the Echo "Close the connection." - releaseDB2 in } the the Echo "Execute SQL ... ..... ....." AboutRun
The following export commands will strip the double quotes of the strings in the exported file:
1 " Export to ${filepath} of Del modified by Nochardel codepage=1208 coldel| ${sql} "
Coldel specifies that the delimiter is |
If you need to keep the string double quote command:
1 " Export to ${filepath} of Del modified by codepage=1208 coldel| ${sql} "
Shell script Implementation DB2 database table export to file