java调用SSIS java调用dtsx包 代码+图示

来源:互联网 发布:淘宝打假人 编辑:程序博客网 时间:2024/05/22 06:07

今天,主管让研究SSIS,网上找了些资料,用VS2005,做了一个简单的资料导入功能。有了.dtsx文件

可是要怎么应用到我的java web程序呢。苦于网上资料很少,去微软的msdn上提问了,也无果。

去google上搜索,翻了好多页,终于找到了,不过是英文的,翻译出来,啊哈,看到了,代码如下:

/**
 * Copyright (c) eBizprise, Inc All Rights Reserved.
 */

package com.ebizprise.project.newhoemwork.common;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.DataInputStream;

/**
 * java 调用SSIS
 * SSISCaller
 * @author Jack.Wang
 * @version 1.0, Created on 2011-2-25 下午04:57:20
 */
public class SSISCaller {

    public static void main(String[] args) {

        try {

            // create the execution process

            Process executionProcess = Runtime.getRuntime().exec("dtexec /f \"f:/temp/dts/Package.dtsx\"");//这个地方要写你做好的dtsx文件的路径

            // create the output reader

            BufferedReader output = new BufferedReader(new InputStreamReader(new DataInputStream(
                    executionProcess

                    .getInputStream())));

            String readStr;

            while ((readStr = output.readLine()) != null) {

                System.out.println(readStr);

            }

            output.close();

            // wait for the process to terminate

            executionProcess.waitFor();

            // check the exit value

            if (executionProcess.exitValue() == 0) {

                System.out.println("SSIS execution succeeded\n");

            } else {

                System.out.println("SSIS execution failed\n");

            }

        } catch (Throwable e) {

            System.out.println(e.getMessage());

        }

    }

    // end of main

}

哇嘎嘎,果然,执行成功了。

这时候,看到有乱码出现,找到代码中的:

BufferedReader output = new BufferedReader(new InputStreamReader(new DataInputStream(
                    executionProcess.getInputStream())));

修改为:

            BufferedReader output = new BufferedReader(new InputStreamReader(new DataInputStream(
                    executionProcess.getInputStream()),"gbk"));

乱码问题解决了

原创粉丝点击