我是一名java程序员。我需要先实现一个功能,就是我开发的Java软件可以连接远程SAS服务器,传一个脚本给他执行,并将结果返回给我的程序。我尝试阅读了许多文件,但仍然没有准确的结果告诉我如何进行。请帮我
Thank you for your reply. This method has been adopted by me before, but we have a session problem that cannot be solved. We need to run multiple scripts at the same time, but they must be executed in the same session in order to obtain the context of each other and execute successfully. If you use bat, you can only execute one script at a time sas 。 Do you know how to solve my problem?
Java连接SAS服务器提交SAS代码运行例子:
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import org.omg.CORBA.StringHolder;
import com.sas.iom.SAS.IBinaryStream;
import com.sas.iom.SAS.IFileService;
import com.sas.iom.SAS.IFileref;
import com.sas.iom.SAS.ILanguageService;
import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.iom.SAS.StreamOpenMode;
import com.sas.iom.SASIOMDefs.OctetSeqHolder;
import com.sas.services.connection.BridgeServer;
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;
public class DownloadOutput {
/**
* @param args
*/
public static void main(String[] args) {
try {
String classID = Server.CLSID_SAS;
String host = "t3207.na.sas.com";
int port = 8591;
Server server = new BridgeServer(classID, host, port);
// TODO Auto-generated method stub
ConnectionFactoryConfiguration cxfConfig = new ManualConnectionFactoryConfiguration(
server);
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);
String user = "sasdemo";
String password = "Orion123";
ConnectionInterface cx = cxf.getConnection(user, password);
org.omg.CORBA.Object obj = cx.getObject();
IWorkspace sasWorkspace = IWorkspaceHelper.narrow(obj);
IFileService fileService = sasWorkspace.FileService();
StringHolder outstring = new StringHolder();
IFileref fileRef = fileService.AssignFileref("out", "TEMP", "", "",
outstring);
ILanguageService languageService = sasWorkspace.LanguageService();
String sasCode = "goptions reset=all gsfname=out gsfmode=replace dev=pdf; proc gchart data=sashelp.class;vbar age / discrete;run;quit;";
languageService.Submit(sasCode);
IBinaryStream fileStream = fileRef
.OpenBinaryStream(StreamOpenMode.StreamOpenModeForReading);
BufferedOutputStream fos = new BufferedOutputStream(
new FileOutputStream("c:\\temp\\test.pdf"));
boolean readMore = true;
OctetSeqHolder tempData = new OctetSeqHolder();
while (readMore) {
fileStream.Read(1024, tempData);
if (tempData.value.length == 0) {
readMore = false;
} else {
fos.write(tempData.value);
}
}
fileStream.Close();
fos.close();
cx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!