使用Java程序顺序读取大型机数据集

时间:2018-03-12 02:46:53

标签: java mainframe

我正在尝试使用Java程序读取大型机顺序数据集。

我的Java代码:

@Override public Compte consulterCompte(String code) throws NotFoundException {
    Optional<Compte> cp = compteRepository.findById(code);
    return cp.orElseThrow(
        () ->  new NotFoundException("Unable to get Account with Code = " + code)
    );  
}

我尝试使用以下JCL编译此代码。

import java.io.IOException;
import com.ibm.recordio.*;

public class Sequential {

    public static void main(String[] args) {

                try {
                    IRecordFile file = RecordFile.getInstanceOf("//" + args[0]);
                    IRandomAccessRecordFile randomFile = RandomAccessRecordFile.getInstanceOf(file, IConstants.JRIO_READ_MODE);
                    readSequentially(randomFile);
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(8);
                }
            }

            // Reads the randomly accessible file sequentially.
            private static void readSequentially(IRandomAccessRecordFile randomFile) throws IOException {
                byte[] buffer = new byte[randomFile.getRecordLength()];
                // Position at the beginning of the file.
                randomFile.positionFirst();
                while (randomFile.read(buffer) != -1) {
                    // Read bytes into buffer. Do something...
                    System.out.println(new String(buffer));
                }
            }


}

我收到了错误 - //DMKSAMP1 JOB ('3000-000000-00-Z-00000000000'), // 'P19314881-090817-0-S',REGION=0M, // CLASS=G,MSGCLASS=H,NOTIFY=&SYSUID /*JOBPARM LINECT=0,ROOM=ZZZZ /*ROUTE PRINT PARSIP0 //BPXBATCH EXEC PGM=BPXBATCH, // PARM='SH javac /u/dmksn/Sequential.java', // REGION=0M //STDOUT DD SYSOUT=* //STDERR DD SYSOUT=* //STDENV DD DUMMY 。如何成功编译程序需要做什么?

2 个答案:

答案 0 :(得分:0)

com.ibm.recordio是IBM Java Record I / O(JRIO)的一部分,在撰写本文时,大约十年前从IBM Java SDK 6.0.1开始就被弃用。

IBM recommends迁移到IBM JZOS工具包。这是您的z / OS Systems Programmer将安装的内容。

答案 1 :(得分:0)

如前所述,JRIO已经被弃用了,谢天谢地,因为它是一个糟糕的API!要读取顺序数据集,您一定要使用JZOS RecordReader类。它使用BSAM重叠I / O,并且明显快于常规ZFile,这是一个比C stdio更简单的JNI包装器。

 String ddname = ZFile.allocDummyDDName();
 String cmd = "alloc fi("+ddname+") da(HLQ.MYDATA) reuse shr msg(2)";
 ZFile.bpxwdyn(cmd);
 RecordReader reader = null;
 try {
   reader = RecordReader.newReaderForDD(ddname);
   byte[] recordBuf = new byte[reader.getLrecl()];
   while ((bytesRead = reader.read(recordBuf)) >= 0) {
     ...
   }
 } finally {
   if (reader != null) {
     try {
       reader.close(); 
     } catch (ZFileException zfe) {
       zfe.printStackTrace();  // but continue
     } 
   }
   try {
     ZFile.bpxwdyn("free fi(" + ddname + ") msg(2)");
   } catch (RcException rce) {
     rce.printStackTrace();  // but continue
   }
 }