码迷,mamicode.com
首页 > 其他好文 > 详细

批量装载数据

时间:2018-07-09 11:04:23      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:src   jdb   return   ext   sele   ret   tab   gets   color   

 

var srcDs="zjkvta";
var destDs = "loadgsdw";

function main(args) {
    copyData(srcDs, "F_ZJLRLC", destDs, "TEST_F_ZJLRLC");
}

/**
 * 
 * @param srcDs 源数据所在数据源名
 * @param srcTableName 查询源数据SQL
 * @param destDs 转换的数据
 * @param destTableName 转换的目的表数据
 */
function copyData(srcDs, srcTableName, destDs, destTableName){
    var logfile = sz.sys.getWorkDir() + "/log.txt";
    println("开始抽取:"+srcTableName);
    var ds = sz.db.getDataSource(srcDs);
    var conn = ds.getConnection();
    try {
        var stmt = conn.createStatement();
        try {
            var ss = (new Date()).getTime();
            var rs = stmt.executeQuery("select * from "+srcTableName);
            try{
                var rowCount = loadTable(rs, destDs, destTableName);
                var ee = (new Date()).getTime();
                var info = "耗时 " + (ee - ss);
                println("抽取完成:"+srcTableName+info+",迁移行数:"+rowCount);
            }finally{
                rs.close();
            }
        } finally {
            stmt.close();
        }
    } finally {
        conn.close();
    }
}

/**
 * 
 */
function loadTable(srcResultSet, destDataSource, destTableName) {
    var ds = sz.db.getDataSource(destDataSource);
    try {
        var conn = ds.getConnection();
        var realConn = conn.getSourceConnection().getConnection();

        var bulkLoader = com.ddtek.jdbc.extensions.DDBulkLoadFactory.getInstance(realConn);
        try {
            bulkLoader.setTableName(destTableName);
            return bulkLoader.load(srcResultSet);
        } finally {
            bulkLoader.close();
        }
    } finally {
        conn.close();
    }
}

 

批量装载数据

标签:src   jdb   return   ext   sele   ret   tab   gets   color   

原文地址:https://www.cnblogs.com/sorliran/p/9282137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!