CSDN博客

img AnyJack

SAS9-IT技术应用-通过JAVA访问SAS实例

发表于2004/9/27 13:46:00  2947人阅读

分类: SAS SAS 第三方开发专栏

在配置好SAS的IT后,其容许JAVA通过Bridge技术访问IT,下面写一个测试例子,通过JAVA执行DATA STEP,并获得返回的日志信息

//Untitled1.java


import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.iom.SAS.ILanguageService;
import com.sas.iom.SAS.ILanguageService;
import com.sas.iom.SAS.ILanguageServicePackage.CarriageControlSeqHolder;
import com.sas.iom.SAS.ILanguageServicePackage.LineTypeSeqHolder;
import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SASIOMDefs.StringSeqHolder;
import com.sas.services.connection.BridgeServer;
import com.sas.services.connection.ConnectionFactoryAdminInterface;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.services.connection.Server;

import java.util.*;
import java.io.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;


public class Untitled1 {
  public Untitled1() {
  }

  static public void main(String[] argv){

// identify the IOM server
    String classID = Server.CLSID_SAS;
    String host = "wuyz";
    int port = 8591;
    Server server = new BridgeServer(classID, host, port);
    try{
// make a connection factory configuration with the server
      ConnectionFactoryConfiguration cxfConfig =
          new ManualConnectionFactoryConfiguration(server);

// get a connection factory manager
      ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();

// get a connection factory that matches the configuration
      ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);

// get the administrator interface
      ConnectionFactoryAdminInterface admin = cxf.getAdminInterface();

// get a connection
      String userName = "sasadm";
      String password = "sas";
System.out.println("----------------------- connnect.... ");
      ConnectionInterface cx = cxf.getConnection(userName, password);
      org.omg.CORBA.Object obj = cx.getObject();
      IWorkspace iWorkspace = IWorkspaceHelper.narrow(obj);

      ILanguageService sasLanguage = iWorkspace.LanguageService();
      /*excute a examle data step.*/
      sasLanguage.Submit("data a;x=1;run;proc print;run;");

      /*get SAS log.*/
      CarriageControlSeqHolder logCarriageControlHldr =
         new CarriageControlSeqHolder();
      LineTypeSeqHolder logLineTypeHldr = new LineTypeSeqHolder();
      StringSeqHolder logHldr = new StringSeqHolder();
      sasLanguage.FlushLogLines(Integer.MAX_VALUE,logCarriageControlHldr,
                                logLineTypeHldr,logHldr);
      String[] logLines = logHldr.value;
      CarriageControlSeqHolder listCarriageControlHldr =
         new CarriageControlSeqHolder();
      LineTypeSeqHolder listLineTypeHldr = new LineTypeSeqHolder();
      StringSeqHolder listHldr = new StringSeqHolder();
      sasLanguage.FlushListLines(Integer.MAX_VALUE,listCarriageControlHldr,
                                 listLineTypeHldr,listHldr);
      String[] listLines = listHldr.value;

      System.out.println("-----------------------------SAS---------------------");
      for(int i=0 ; i < listLines.length;i++){
        System.out.println(listLines[i]);
      }
      System.out.println("-----------------------------SAS  END----------------");

      cx.close();
System.out.println("----------------------- connnect is close.... ")  ;

// tell the factory that it can destroy unused connections
      admin.shutdown();
System.out.println("----------------------- is shutdown.... ")        ;
    }catch(Exception e){
      e.printStackTrace();
    }
  }

阅读全文
0 0

相关文章推荐

img
取 消
img