gpt4 book ai didi

java - 如何使用 Java 代码添加 DB2 库来调用 AS400 PGM

转载 作者:行者123 更新时间:2023-11-30 10:06:38 35 4
gpt4 key购买 nike

我正在使用 Java 代码调用 AS400 程序。当程序很简单并且不尝试写入任何 DB2 表时,调用成功。当我尝试调用另一个试图写入 DB2 表的程序时,它没有成功,因为我必须添加与该表相关的 DB2 库。我必须使用 java 代码添加库。使用 coldfusion 代码向我提供了一个示例来添加这些库。我想知道如何使用 Java 代码添加 DB2 库。

private static final String HOST = "XXX.XXX.XXX.XXX";
private static final String UID = "XXX";
private static final String PWD = "XXX";

String fullProgramName = "/QSYS.LIB/TSTOBJ.LIB/GETAB.PGM";
String input = "12345678";
AS400 as400 = null;
byte[] inputData;
byte[] outputData;
String SCAB;
AS400Text textData;
ProgramParameter[] parmList;
ProgramCall programCall;

try {
// Create an AS400 object
as400 = new AS400(HOST, UID, PWD);
// Create a parameter list
// The list must have both input and output parameters
parmList = new ProgramParameter[2];
// Convert the Strings to IBM format

inputData = input.getBytes("IBM285");

// Create the input parameter

parmList[0] = new ProgramParameter(inputData);

// Create the output parameter
//Prarameterised Constructor is for the OUTPUT LENGTH. here it is 10
parmList[1] = new ProgramParameter(20);


/**
* Create a program object specifying the name of the program and
* the parameter list.
*/
programCall = new ProgramCall(as400);
programCall.setProgram(fullProgramName, parmList);
// Run the program.
if (!programCall.run()) {
/**
* If the AS/400 is not run then look at the message list to
* find out why it didn't run.
*/
AS400Message[] messageList = programCall.getMessageList();
for (AS400Message message : messageList) {
System.out.println(message.getID() + " - " + message.getText());

}
} else {
/**
* Else the program is successfull. Process the output, which
* contains the returned data.
*/
outputData = parmList[1].getOutputData();
SCAB = new String(outputData, "IBM285").trim();

/* System.out.println("Output is " + SCAB );*/
}

} catch (PropertyVetoException | AS400SecurityException | ErrorCompletingRequestException | IOException | InterruptedException | ObjectDoesNotExistException e) {
System.err.println(":: Exception ::" + e.toString());
} finally {
try {
// Make sure to disconnect
if (as400 != null) {
as400.disconnectAllServices();
}
} catch (Exception e) {
System.err.println(":: Exception ::" + e.toString());
}

COLDFUSION 代码=====>>>

<CFSET MYCMD = "ADDLIBLE KINP#Application.EQ_UNIT#   "  >
<cfset vretval = vcommand.run("#MYCMD#") >

<CFSET MYCMD = "ADDLIBLE KFIL#Application.EQ_UNIT# " >
<cfset vretval = vcommand.run("#MYCMD#") >

<CFSET MYCMD = "ADDLIBLE KWRK#Application.EQ_UNIT# " >
<cfset vretval = vcommand.run("#MYCMD#") >

<CFSET MYCMD = "ADDLIBLE KLIB#Application.EQ_UNIT# " >
<cfset vretval = vcommand.run("#MYCMD#") >

<CFSET MYCMD = "ADDLIBLE LIBK311F " >
<cfset vretval = vcommand.run("#MYCMD#") >

最佳答案

使用命令调用来执行命令。有关详细信息,请参阅以下链接。

https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/rzahh/javadoc/com/ibm/as400/access/CommandCall.html

关于java - 如何使用 Java 代码添加 DB2 库来调用 AS400 PGM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54557579/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com