国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

IBM DB2 數(shù)據(jù)復(fù)制遷移方法

瀏覽:101日期:2023-11-11 11:53:26
背景:需要更改數(shù)據(jù)庫(kù)表空間,或者需要將數(shù)據(jù)庫(kù)中所有表的數(shù)據(jù)遷移到一個(gè)新的數(shù)據(jù)庫(kù)中。步驟:1.通過db2控制臺(tái)(db2cc)選中源數(shù)據(jù)庫(kù)中的所有表,將其導(dǎo)出成DDL腳本;2.根據(jù)需要對(duì)腳本進(jìn)行必要的修改,譬如更改表空間為GATHER;3.新建數(shù)據(jù)庫(kù),新建DMS表空間:GATHER;4.將DDL腳本在此數(shù)據(jù)庫(kù)中執(zhí)行;5.編寫代碼查詢?cè)磾?shù)據(jù)庫(kù)中的所有表,自動(dòng)生成export腳本;6.編寫代碼查詢?cè)磾?shù)據(jù)庫(kù)中的所有表,自動(dòng)生成import腳本;7.連接源數(shù)據(jù)庫(kù)執(zhí)行export腳本;8.連接目標(biāo)數(shù)據(jù)庫(kù)執(zhí)行import腳本;附錄1:生成export腳本代碼示例:/*** 創(chuàng)建導(dǎo)出腳本* @param conn* @param creator 表創(chuàng)建者* @param filePath*/* 創(chuàng)建導(dǎo)出腳本* @param conn* @param creator 表創(chuàng)建者* @param filePathpublic void createExportFile(Connection conn,String creator,String filePath) throws Exception {DBBase dbBase = new DBBase(conn);String selectTableSql = "select name from sysibm.systables where creator = '" + creator + "' and type='T'";try {dbBase.executeQuery(selectTableSql);} catch (Exception ex) {throw ex;} finally {dbBase.close();}DBResult result = dbBase.getSelectDBResult();List list = new ArrayList();while (result.next()) {String table = result.getString(1);list.add(table);}StringBuffer sb = new StringBuffer();String enterFlag = "";for (int i = 0; i < list.size();i++) {String tableName = (String)list.get(i);sb.append("db2 "export to aa" + String.valueOf(i+1)+ ".ixf of ixf select * from " + tableName + """);sb.append(enterFlag);}String str = sb.toString();FileUtility.saveStringToFile(filePath, str, false);}附錄2:生成import腳本代碼示例/*** 創(chuàng)建裝載腳本* @param conn* @param creator 表創(chuàng)建者* @param filePath*/public void createLoadFile(Connection conn,String creator,String filePath) throws Exception {DBBase dbBase = new DBBase(conn);String selectTableSql = "select name from sysibm.systables where creator = '" + creator + "' and type='T'";try {dbBase.executeQuery(selectTableSql);} catch (Exception ex) {throw ex;} finally {dbBase.close();}DBResult result = dbBase.getSelectDBResult();List list = new ArrayList();while (result.next()) {String table = result.getString(1);list.add(table);}StringBuffer sb = new StringBuffer();String enterFlag = "";for (int i = 0; i < list.size();i++) {String tableName = (String)list.get(i);sb.append("db2 "load from aa" + String.valueOf(i+1)+ ".ixf of ixf into " + tableName + " COPY NO without prompting "");sb.append(enterFlag);}String str = sb.toString();FileUtility.saveStringToFile(filePath, str, false);}附錄3:export腳本示例db2connecttotestdbusertestpasswordtestdb2"exporttoaa1.ixfofixfselect*fromtable1"db2"exporttoaa2.ixfofixfselect*fromtable2"db2connectreset附錄4:import腳本示例db2connecttotestdbusertestpasswordtestdb2"loadfromaa1.ixfofixfreplaceintotable1COPYNOwithoutprompting"db2"loadfromaa2.ixfofixfreplaceintotable2COPYNOwithoutprompting"db2connectreset
標(biāo)簽: DB2 數(shù)據(jù)庫(kù)
主站蜘蛛池模板: 岳阳市| 镇宁| 济源市| 日土县| 建宁县| 宝山区| 石首市| 枣庄市| 扎囊县| 进贤县| 门源| 获嘉县| 太和县| 新竹县| 阿合奇县| 建瓯市| 广德县| 依兰县| 大田县| 班玛县| 广德县| 息烽县| 海城市| 新龙县| 五家渠市| 东城区| 德昌县| 西乌珠穆沁旗| 永泰县| 万源市| 拜城县| 灵璧县| 宕昌县| 河间市| 澄江县| 出国| 泸西县| 湘潭县| 四子王旗| 靖边县| 通化市|