当前位置导航:炫浪网>>网络学院>>编程开发>>JAVA教程>>J2EE

通过JAVA、VB访问SAS IOM服务器

    添加SAS JAR.RAR中的JAR包。

    运行以下代码:

文件: SAS jar.rar 大小: 1581KB 下载: 点击

import java . rmi . RemoteException ;
import java . sql . ResultSet ;
import java . util . Properties ;

import com.sas.iom.WorkspaceFactory;
import com.sas.iom.SAS.IDataService;
import com.sas.iom.SAS.ILanguageService;
import com.sas.iom.SAS.IWorkspace;
import com.sas.rio.MVAConnection;




publicclass CreditServiceImpl implementsjava.rmi.Remote
{
    
    privateString HOST ="localhost";
    privateStringPORT="8591";
    privateString JDBS_DRIVER_NAME ="com.sas.rio.MVADriver";
    privateString JDBS_DATEBASE_URL ="jdbc:sasiom://localhost:8591";
    privateString SAS_USER ="sasadm";
    privateString SAS_PWD ="sas123?";
    
    
   publicResultSet getCreditLimit(String libnamestr,Stringsql)throwsjava.rmi.RemoteException
   {

     java.sql.Connectionconnection=null;
     java.sql.Statementstatement=null;
     java.sql.ResultSet rs =null;
     IWorkspace iWorkspace          =null;
     WorkspaceFactory wsf          =null;
    
      try
      {
         wsf =new WorkspaceFactory();
        
         Properties serverInfo =newProperties();
         
         serverInfo.put("host", HOST);
         serverInfo.put("port",PORT);
         serverInfo.put("userName", SAS_USER);
         serverInfo.put("password", SAS_PWD);
         
         iWorkspace = wsf.createWorkspaceByServer(serverInfo);

         ILanguageService iLang = iWorkspace.LanguageService();

         //String libnamecm = "libname libstg 'e:\\data';";


         
          ILanguageService sasLanguage = iWorkspace.LanguageService();
         
          sasLanguage.Submit(libnamestr);

         Stringlog= iLang.FlushLog(50000);
         
         System.out.println(log);
                
         /* Read the result via an MVAConnection */
         IDataService iDataService = iWorkspace.DataService();

         connection=new MVAConnection(iDataService,newProperties());
         statement=connection.createStatement();
         //String sql = "Select * from libstg.userinfo";

         
         System.out.println("Curr Libname Command: "+ libnamestr);
         System.out.println("");
         System.out.println("Curr Running SQL :"+sql);
         
         
         rs =statement.executeQuery(sql);

// if( rs.next() )

// {

// String UserName = rs.getString("userName");

// System.out.println(UserName);

// }

      }
      catch(Throwable t )
      {
         t.printStackTrace();
         java.rmi.RemoteException ex =newjava.rmi.RemoteException("Error getting credit limit", t);
         throw ex;
      }
      finally{
         try{
            /* Close JDBC connection if open */
            if(connection!=null)
            {
               if(!connection.isClosed())
                  connection.close();
            }

            /* Close iWorkspace */
            if(iWorkspace !=null)
               iWorkspace.Close();

            /* Shutdown WorkspaceFactory */
            if(wsf !=null)
               wsf.shutdown();
         }catch(Throwable t){
            //t.printStackTrace();

         }
      }
      return rs;
 }

 


    /**
     * @param args
     */

    publicstaticvoid main(String[] args){
        // TODO 自动生成方法存根

        
        CreditServiceImpl csi =new CreditServiceImpl();
        Stringsql="Select * from libstg.userinfo";
        String libnamecm ="libname libstg 'e:\\data';";
        try{
            csi.getCreditLimit(libnamecm,sql);
        }catch(RemoteException e){
            // TODO 自动生成 catch 块

            e.printStackTrace();
        }

    }

}

 

共4页 首页 上一页 1 2 3 4 下一页 尾页 跳转到
相关内容
赞助商链接