• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Windows下使用Perl連接DB2

            Posted on 2010-01-25 11:17 Prayer 閱讀(485) 評(píng)論(0)  編輯 收藏 引用 所屬分類: PERL
            本文是參考了<DB2 Magazine Quarter 1. 2005. VOLUME 10 NUMBER 1>;雜志里的<Perls of Wisdom-Follow these simple steps to use the free Perl language with DB2>;一文,可以說是一個(gè)摘抄(不同的是文章是中文)
            原文參見http://www.db2mag.com/story/showArticle.jhtml?articleID=59301551

            1. Perl的DB2驅(qū)動(dòng)
            Perl語(yǔ)言本身就不多做介紹了。
            1994年發(fā)布的DBI是Perl語(yǔ)言連接關(guān)系性數(shù)據(jù)庫(kù)的標(biāo)準(zhǔn)。可以從dbi.perl.org獲得DBI的源代碼和文檔。
            IBM在1995年發(fā)布了對(duì)于Perl的DB2驅(qū)動(dòng),這個(gè)驅(qū)動(dòng)是符合DBI標(biāo)準(zhǔn)的,在Perl里這個(gè)驅(qū)動(dòng)稱為DBD::DB2 。可以從ibm.com/software/db2/perl獲得DBD::DB2驅(qū)動(dòng)的最新信息。

            注意:最近的DB2驅(qū)動(dòng)需要至少Perl 5.005_03和DBI 1.21或以上的版本。

            2. 準(zhǔn)備環(huán)境
            步驟如下
            (1)安裝Perl語(yǔ)言環(huán)境
            Windows下可以從www.activestate.com獲得Perl的安裝包。
            安裝后可以使用perl -v看看Perl的版本信息。
            DBI驅(qū)動(dòng)和DBD::DB2驅(qū)動(dòng)都是作為Perl的附加模塊使用ppm工具安裝的。安裝方法參見(2), (3),安裝時(shí)最好先去ibm.com/software/db2/perl上看看ppm后面的參數(shù)有沒有變化。

            (2)安裝DBI驅(qū)動(dòng)
            ppm install http://ftp.esoftmatic.com/outgoing/DBI/5.8.4/DBI.ppd

            (3)安裝DBD::DB2驅(qū)動(dòng)
            ppm install http://ftp.esoftmatic.com/outgoing/DBI/5.8.4/DBD-DB2.ppd

            (4)安裝DB2 runtime client


            3. 使用Perl連接DB2
            (1)使用DBI函數(shù)DBI->;data_sources 來掃描DB2數(shù)據(jù)庫(kù)目錄并返回一個(gè)包含了有效數(shù)據(jù)源名稱(DSN)的數(shù)組。
            ----------------datasources.pl-------------
            #!/usr/lib/perl -w
            #
            # This perl script prints the list of cataloged DB2 data-sources
            #
            use DBI;
            use DBD::DB2;
            use DBD::DB2::Constants;

            print "Operating Systems = $^O\n";
            print "Perl Binary = $^X\n";
            print "Perl Version = $]\n";
            print "DBI Version = $DBI::VERSION\n";
            print "DBD::DB2 Version = $DBD::DB2::VERSION\n\n";

            my @DB2DataSources = DBI->;data_sources("DB2");

            print "Available DB2 DSNs:\n\n";

            foreach my $dsn ( @DB2DataSources )
            {
            print " $dsn \n";
            }
            -------------------END----------------------

            (2)獲取db2數(shù)據(jù)庫(kù)的信息
            ----------datasourceInfo.pl--------------------------
            #!/usr/lib/perl -w
            #
            # This perl script prints the information DB2 database
            #
            use DBI;
            use DBD::DB2;
            use DBD::DB2::Constants;

            my $dsn = 'dbi:DB2:SAMPLE';
            my $uid = 'henry';
            my $pwd = 'happyday';

            my $dbh = DBI->;connect( $dsn, $uid, $pwd )           || die "$DBI::errstr";

            print "Database Connection Information \n\n";
            printf( "Server Instance     : %s\n", $dbh->;get_info( SQL_SERVER_NAME ) );
            printf( "Database Server     : %s\n", $dbh->;get_info( SQL_DBMS_NAME ) );
            printf( "Database Version    : %s\n", $dbh->;get_info( SQL_DBMS_VER ) );  
            printf( "Database Alias      : %s\n", $dbh->;get_info( SQL_DATA_SOURCE_NAME ) );
            printf( "Database Codepage   : %s\n", $dbh->;get_info( 2519 ) );
            printf( "Application Codepage: %s\n", $dbh->;get_info( 2520 ) );
            printf( "Authoriztion Id     : %s\n", $dbh->;get_info( SQL_USER_NAME ) );
            printf( "Max Idntifier Len   : %s\n", $dbh->;get_info( SQL_MAX_IDENTIFIER_LEN ) );
            printf( "Max Table Name Len  : %s\n", $dbh->;get_info( SQL_MAX_TABLE_NAME_LEN ) );
            printf( "Max Index Size      : %s\n", $dbh->;get_info( SQL_MAX_INDEX_SIZE ) );
            printf( "Max Columns in Table: %s\n", $dbh->;get_info( SQL_MAX_COLUMNS_IN_TABLE ) );
            -------------------END----------------------

            (3)獲取db2數(shù)據(jù)庫(kù)的元數(shù)據(jù)(比如, 表結(jié)構(gòu))
            ----------tableinfo.pl--------------------------
            #!/usr/lib/perl -w
            #
            # This perl script prints the information of cataloged DB2 table
            #
            use DBI;
            use DBD::DB2;
            use DBD::DB2::Constants;

            $dsn = 'dbi:DB2:SAMPLE';
            $uid = 'henry';
            $pwd = 'happyday';

            # Connect to the SAMPLE database
            $dbh = DBI->;connect( $dsn, $uid, $pwd )           || die "$DBI::errstr";

            # Get the tables for schema HENRY
            $sth = $dbh->;table_info( { 'TABLE_CSHEM' =>; "HENRY" } );

            $table_counter = 0;
            while ( @row = $sth->;fetchrow_array )
            {
            $catalog = $row[0];
            $schema = $row[1];
            $table = $row[2];

            $table_counter++;
            printf( "Table %d %s\n", $table_counter, $table );

            # Now get the column information for this table
            $sth_col = $dbh->;column_info( $catalog, $schema, $table, '%' );
            if( $sth_col )
            {
            while( @row_col = $sth_col->;fetchrow_array )
            {
            # @row_col has a lot more information. I'll just take
            # these three fields as an example
            $column_name = $row_col[3];
            $type_name   = $row_col[5];
            $column_size = $row_col[6];

            printf( "  %-24s%s(%s)\n", $column_name, $type_name, $column_size );
            }

            $sth_col->;finish();
            }
            }

            $sth->;finish();
            $dbh->;disconnect;
            -------------------END----------------------

            (4)執(zhí)行SQL
            ----------executesql.pl--------------------------
            #!/usr/lib/perl -w
            #
            # This perl script manipulate DB2 table
            #
            use DBI;
            use DBD::DB2;
            use DBD::DB2::Constants;

            $dsn = 'dbi:DB2:SAMPLE';
            $uid = 'henry';
            $pwd = 'happyday';

            # Connect to the SAMPLE database
            $dbh = DBI->;connect( $dsn, $uid, $pwd )           || die "$DBI::errstr";

            # Prepare our insert statement
            $sth = $dbh->;prepare( "INSERT INTO sales VALUES('2005-06-25', 'Tom', 'Beijing', 15)");
            $sth->;execute();
            $sth->;finish();
            $dbh->;disconnect;
            -------------------END----------------------
            国产精品美女久久久久久2018| 久久黄视频| 精品久久久久久久| 久久伊人精品青青草原日本| 久久国语露脸国产精品电影| 大伊人青草狠狠久久| 久久综合久久性久99毛片| 精产国品久久一二三产区区别 | 中文字幕人妻色偷偷久久 | 欧洲人妻丰满av无码久久不卡| www.久久热.com| 久久精品桃花综合| 国产成人精品久久亚洲高清不卡| 久久午夜福利无码1000合集| 成人国内精品久久久久影院VR| 亚洲午夜久久久影院伊人| 久久er国产精品免费观看8| 麻豆AV一区二区三区久久| 深夜久久AAAAA级毛片免费看| 久久免费高清视频| 精品无码久久久久久尤物| 99久久国产综合精品女同图片| 色综合合久久天天给综看| 国产亚州精品女人久久久久久| 久久久久久亚洲Av无码精品专口 | 久久综合狠狠综合久久97色| 久久久久久久尹人综合网亚洲| 中文国产成人精品久久不卡| 久久精品国产欧美日韩99热| 日韩精品久久无码中文字幕| 久久av免费天堂小草播放| 成人久久综合网| 久久久久久毛片免费播放| 精品国产青草久久久久福利| 久久久午夜精品| 狠狠色噜噜色狠狠狠综合久久| 久久国产亚洲精品| 久久无码国产专区精品| 久久天天躁狠狠躁夜夜avapp| 久久久久亚洲AV成人网人人网站| 久久久久久久国产免费看|