In Java, Jacob calls DTS to import and export data.

Source: Internet
Author: User
In Java, Jacob calls DTS to import and export data.

Keywords: Java Jacob DTS Import and Export

Step 1:
Download Jacob
Http://danadler.com/jacob/jacobBin_17.zip
Decompress the package and put the DLL file in the % java_home %/JRE/bin directory. Put the JAR file in the % java_home %/JRE/lib/EXT directory without configuring environment variables.

Step 2:
Create a data transmission file
Create a data transmission task using the SQL Server Import and Export tool and save it as a storage structure file, for example, D:/temp/DTS/dts_test.dts

Step 3:
Use Java to call the DTs file to execute data import and export Java code

  1. PackageDBF;
  2. ImportJava. Text. simpledateformat;
  3. ImportJava. util. date;
  4. ImportCom. Jacob. ActiveX .*;
  5. ImportCom.jacb.com .*;
  6. Public ClassExportdts {
  7. Public VoidExportdbf (){
  8. Simpledateformat localtime =NewSimpledateformat ("yyyy-mm-dd hh: mm: SS ");
  9. String importfilename = "D:/temp/DBF"; // The Path to store the exported DBF
  10. String dtspath = "D:/temp/DTS/dts_test.dts"; // the path of the DTs File
  11. Try{
  12. System. Out. println ("START:" + localtime. Format (NewDate ()));
  13. Activexcomponent APP =NewActivexcomponent ("DTS. package2 ");
  14. Dispatch. calln (app, "loadfromstoragefile ",NewVariant [] {NewVariant (dtspath ),NewVariant ("")});
  15. // Reset the path
  16. Dispatch dtsconns = Dispatch. Get (app, "Connections"). todispatch ();
  17. Dispatch dtsconn = Dispatch. calln (dtsconns, "item ",NewVariant [] {NewVariant (2)}). todispatch ();
  18. Dispatch. Put (dtsconn, "datasource ",NewString (importfilename ));
  19. // Execute
  20. Dispatch. calln (app, "execute ",NewVariant [] {});
  21. // Obtain the execution result
  22. Dispatch dtssteps = Dispatch. Get (app, "Steps"). todispatch ();
  23. Dispatch dtsstep = Dispatch. calln (dtssteps, "item ",NewVariant [] {NewVariant (1)}). todispatch ();
  24. Variant resultvalue = Dispatch. Get (dtsstep, "executionresult ");
  25. If(Resultvalue. toint () = 0 ){
  26. System. Out. println ("exported successfully ");
  27. }Else{
  28. System. Out. println ("Export failed ");
  29. }
  30. System. Out. println ("end:" + localtime. Format (NewDate ()));
  31. }Catch(Exception ex ){
  32. Ex. printstacktrace ();
  33. }
  34. }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.