项目中有一个应用需要应用程序调用dts文件,我在网上找了一个例子,稍作了修改
public static void main(String[] str)
{
SimpleDateFormat localTime = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"); String importFileName = "D:/temp/dbf"; // 这里导出的DBF要存放的路径
String DtsPath = "D:/myfirstdts.dts"; // 这里是DTS文件的路径 try
{
System.out.println("start: " + localTime.format(new Date())); ActiveXComponent app = new ActiveXComponent("DTS.Package2"); Dispatch.callN(app, "LoadFromStorageFile", new Variant[] {
new Variant(DtsPath), new Variant("") }); // 重新设置路径
Dispatch DTSconns = Dispatch.get(app, "Connections").toDispatch();
Dispatch DTSconn = Dispatch.callN(DTSconns, "Item",
new Variant[] { new Variant(2) }).toDispatch();
Dispatch.put(DTSconn, "DataSource", new String(importFileName)); // 执行
Dispatch.callN(app, "Execute", new Variant[] {}); // 得到执行的结果
Dispatch DTSsteps = Dispatch.get(app, "Steps").toDispatch();
Dispatch DTSstep = Dispatch.callN(DTSsteps, "Item",
new Variant[] { new Variant(1) }).toDispatch();
Variant ResultValue = Dispatch.get(DTSstep, "ExecutionResult"); if (ResultValue.toInt() == 0)
{
System.out.println("导出成功 "); }
else
{
System.out.println("导出失败 "); }
System.out.println("end: " + localTime.format(new Date()));
}
catch (Exception ex)
{
ex.printStackTrace(); } }
运行后,我以为会运行我的dts文件,但是总是报("导出失败 "),已没什么异常出现,网上查了半天,没有获得结果,是不是我哪里设置出错了啊,请高人们指点!!!
public static void main(String[] str)
{
SimpleDateFormat localTime = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"); String importFileName = "D:/temp/dbf"; // 这里导出的DBF要存放的路径
String DtsPath = "D:/myfirstdts.dts"; // 这里是DTS文件的路径 try
{
System.out.println("start: " + localTime.format(new Date())); ActiveXComponent app = new ActiveXComponent("DTS.Package2"); Dispatch.callN(app, "LoadFromStorageFile", new Variant[] {
new Variant(DtsPath), new Variant("") }); // 重新设置路径
Dispatch DTSconns = Dispatch.get(app, "Connections").toDispatch();
Dispatch DTSconn = Dispatch.callN(DTSconns, "Item",
new Variant[] { new Variant(2) }).toDispatch();
Dispatch.put(DTSconn, "DataSource", new String(importFileName)); // 执行
Dispatch.callN(app, "Execute", new Variant[] {}); // 得到执行的结果
Dispatch DTSsteps = Dispatch.get(app, "Steps").toDispatch();
Dispatch DTSstep = Dispatch.callN(DTSsteps, "Item",
new Variant[] { new Variant(1) }).toDispatch();
Variant ResultValue = Dispatch.get(DTSstep, "ExecutionResult"); if (ResultValue.toInt() == 0)
{
System.out.println("导出成功 "); }
else
{
System.out.println("导出失败 "); }
System.out.println("end: " + localTime.format(new Date()));
}
catch (Exception ex)
{
ex.printStackTrace(); } }
运行后,我以为会运行我的dts文件,但是总是报("导出失败 "),已没什么异常出现,网上查了半天,没有获得结果,是不是我哪里设置出错了啊,请高人们指点!!!
public static void main(String[] str)
{ try
{
/**
Runtime.getRuntime().exec(
"dtsrun /Sray /Usa /P111111 /Nfirstbag /M111111");//见数据库中本地包,参数说明S后紧跟的是数据库服务器名,U后是访问数据库的用户名,P是访问数据库的密码,N是DTS包的名称,M是访问该包的密码*/
Runtime.getRuntime().exec("dtsrun /FD:/myfirstdts.dts");/**上一种方法是直接对SQLServer2000生成的包进行的操作是可以运行的,这个是对SQLServer2000所有任务中导出数据所生成的dts包文件进行的操作,这2个操作都是可以的*/
System.out.println("Done!");
}
catch (Exception e)
{
e.printStackTrace();
} }