`
sunxuecheng
  • 浏览: 23569 次
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

sql上报数据3

阅读更多
private boolean ociSqlldr(String path, AbstractSqlLoad sqlload)
    {
        // 定义处理状态
        boolean result = false;
        try
        {
            sqlload.setDirectoryFile(getSqlLoadDirectory(), fileName,
                    getColumn(path));
            // 设置用户名、密码、主机IP等参数
            sqlload.setUseId(uName, passwd, getOraNetServerName());
            // SQLLOAD 加载
            result = sqlload.preform();
        }
        catch (Throwable e)
        {
            logger.error("Sqlload datafile " + this.fileName + " failed", e);
        }
        return result;
    }

    /**
     * 使用调用oracle sqlldr工具的方式把数据入库。
     * @param tableName 对应的数据库表名
     * @param sqlldrFilePath sqlldr数据文件路径。
     * @return 入库成功返回true,否则false
     */
    private boolean oracleSqlldr(String tableName, String sqlldrFilePath,
            AbstractSqlLoad sqlload)
    {
        // 定义处理状态
        boolean result = false;

        // 设置用户名、密码、主机IP等参数
        sqlload.setUseId(uName, passwd, getOraNetServerName());

        // 生成控制文件
        GenOraCtrlFile writeCtl = new GenOraCtrlFile();

        try
        {
            ctlFileName = (writeCtl.writeCtl(new File(getSqlLoadDirectory(),
                    fileName).getPath(), tableName)).getPath();
            sqlload.setHome(DASProperties.getOracle_home());
            sqlload.setCtlFile(ctlFileName);

            // 获取日志文件名
            /** SqlLoad日志文件名 */
            String logFileName = configOracleLogFile();

            // 设置要生成的log日志文件
            sqlload.setLogFile(logFileName);

            // 设置要生成的bad文件
            sqlload.setBadFile(configOracleBadFile());

            if (db.equalsIgnoreCase(SCHEMA_DPI_RPT))
            {
                // 实时流量 设置Direct=false
                sqlload.setDirect(false);
            }
            else
            {
                // 默认设置Direct=true
                sqlload.setDirect(true);
            }

            // SQLLOAD 加载
            result = sqlload.preform();

            // 如果数据文件入库失败,把sqlLoad的日志文件写到DAS日志文件中
            if (!result)
            {
                this.readSqlLoadErrLog(logFileName);
            }

            /** 删除SqlLoad日志文件 */
            if (isNeedDelLogFile())
            {
                File logFile = new File(logFileName);
                if (!FileUtil.delete(logFile))
                {
                    logger.error("delete log file failed! the file name is "
                            + logFile.getName());
                }
            }

            // 判断load子进程是否挂死或超时
            if (sqlload.isTimeOut())
            {
                throw new IllegalThreadStateException(
                        "The oracle sqlldr prcess is not determined!");
            }

        }
        catch (Throwable e)
        {
            logger.error("Sqlload datafile " + this.fileName + " failed", e);
        }

        return result;
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics