/**
* 创建导出脚本
* @param conn
* @param creator 表创建者
* @param filePath
*/
* 创建导出脚本
* @param conn
* @param creator 表创建者
* @param filePath
public 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脚本代码示例/**
* 创建装载脚本
* @param conn
* @param creator 表创建者
* @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脚本示例 db2connecttotestdbusertestpassWordtest
db2"exporttoaa1.ixfofixfselect*fromtable1"
db2"exporttoaa2.ixfofixfselect*fromtable2"
db2connectreset
附录4:import脚本示例 db2connecttotestdbusertestpasswordtest
db2"loadfromaa1.ixfofixfreplaceintotable1COPYNOwithoutprompting"
db2"loadfromaa2.ixfofixfreplaceintotable2COPYNOwithoutprompting"
db2connectreset
新闻热点
疑难解答