187 lines
7.3 KiB
HTML
187 lines
7.3 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="reference" />
|
||
|
<meta name="DC.Title" content="Example: Using record-level access (part 1 of 2)" />
|
||
|
<meta name="abstract" content="" />
|
||
|
<meta name="description" content="" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="rlaex1" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>Example: Using record-level access (part 1 of 2)</title>
|
||
|
</head>
|
||
|
<body id="rlaex1"><a name="rlaex1"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: Using record-level access (part 1 of 2)</h1>
|
||
|
<div><p></p>
|
||
|
<div class="section"><p>[ <a href="rlaex2.htm#rlaex2">Next part</a> ]</p>
|
||
|
<p>Use
|
||
|
the following as an example for your program.</p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm#codedisclaimer">Code
|
||
|
example disclaimer</a> for important legal information.</div>
|
||
|
<pre>//////////////////////////////////////////////////////////////////////////////////
|
||
|
//
|
||
|
// Record level access example. This program will prompt the user
|
||
|
// for the name of the server and the file to display. The file must exist
|
||
|
// and contain records. Each record in the file will be displayed
|
||
|
// to System.out.
|
||
|
//
|
||
|
// Calling syntax: java RLSequentialAccessExample
|
||
|
//
|
||
|
// This source is an example of IBM Toolbox for Java "RecordLevelAccess"
|
||
|
//
|
||
|
//////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.util.*;
|
||
|
import com.ibm.as400.access.*;
|
||
|
|
||
|
public class RLSequentialAccessExample
|
||
|
{
|
||
|
public static void main(String[] parameters)
|
||
|
{
|
||
|
BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in),1);
|
||
|
|
||
|
String systemName = "";
|
||
|
String library = "";
|
||
|
String file = "";
|
||
|
String member = "";
|
||
|
|
||
|
System.out.println();
|
||
|
try
|
||
|
{
|
||
|
System.out.print("System name: ");
|
||
|
systemName = inputStream.readLine();
|
||
|
|
||
|
System.out.print("Library in which the file exists: ");
|
||
|
library = inputStream.readLine();
|
||
|
|
||
|
System.out.print("File name: ");
|
||
|
file = inputStream.readLine();
|
||
|
|
||
|
System.out.print("Member name (press enter for first member): ");
|
||
|
member = inputStream.readLine();
|
||
|
if (member.equals(""))
|
||
|
{
|
||
|
member = "*FIRST";
|
||
|
}
|
||
|
|
||
|
System.out.println();
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
System.out.println("Error obtaining user input.");
|
||
|
e.printStackTrace();
|
||
|
System.exit(0);
|
||
|
}
|
||
|
|
||
|
|
||
|
AS400 system = new AS400(systemName); <a href="#rlaex1__dup0013">Note 1 </a>
|
||
|
try
|
||
|
{
|
||
|
system.connectService(AS400.RECORDACCESS);
|
||
|
}
|
||
|
catch(Exception e)
|
||
|
{
|
||
|
System.out.println("Unable to connect for record level access.");
|
||
|
System.out.println("Check the programmer's guide setup file for
|
||
|
special instructions regarding record level access");
|
||
|
e.printStackTrace();
|
||
|
System.exit(0);
|
||
|
}
|
||
|
|
||
|
|
||
|
QSYSObjectPathName filePathName = new QSYSObjectPathName(library, file, member, "MBR"); <a href="#rlaex1__dup0014">Note 2</a>
|
||
|
|
||
|
|
||
|
SequentialFile theFile = new SequentialFile(system, filePathName.getPath()); <a href="#rlaex1__dup0015">Note 3 </a>
|
||
|
|
||
|
|
||
|
AS400FileRecordDescription recordDescription =
|
||
|
new AS400FileRecordDescription(system, filePathName.getPath());
|
||
|
try
|
||
|
{
|
||
|
RecordFormat[] format = recordDescription.retrieveRecordFormat(); <a href="#rlaex1__dup0016">Note 4 </a>
|
||
|
|
||
|
|
||
|
theFile.setRecordFormat(format[0]); <a href="#rlaex1__dup0017">Note 5 </a>
|
||
|
|
||
|
|
||
|
theFile.open(AS400File.READ_ONLY, 100, AS400File.COMMIT_LOCK_LEVEL_NONE); <a href="#rlaex1__dup0018">Note 6 </a>
|
||
|
|
||
|
System.out.println("Displaying file " + library.toUpperCase() + "/" +
|
||
|
file.toUpperCase() + "(" + theFile.getMemberName().trim() + "):");
|
||
|
|
||
|
Record record = theFile.readNext(); <a href="#rlaex1__dup0019">Note 7 </a>
|
||
|
while (record != null)
|
||
|
{
|
||
|
System.out.println(record);
|
||
|
record = theFile.readNext();
|
||
|
}
|
||
|
System.out.println();
|
||
|
|
||
|
|
||
|
theFile.close(); <a href="#rlaex1__eight">Note 8 </a>
|
||
|
|
||
|
|
||
|
system.disconnectService(AS400.RECORDACCESS); <a href="#rlaex1__nine">Note 9 </a>
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
System.out.println("Error occurred attempting to display the file.");
|
||
|
e.printStackTrace();
|
||
|
|
||
|
try
|
||
|
{
|
||
|
// Close the file
|
||
|
theFile.close();
|
||
|
}
|
||
|
catch(Exception x)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
system.disconnectService(AS400.RECORDACCESS);
|
||
|
System.exit(0);
|
||
|
}
|
||
|
|
||
|
// Make sure that the application ends; see readme for details
|
||
|
System.exit(0);
|
||
|
}
|
||
|
}</pre>
|
||
|
<div class="fignone"></div>
|
||
|
</div>
|
||
|
<div class="section"><ol><li id="rlaex1__dup0013"><a name="rlaex1__dup0013"><!-- --></a>This line of code creates an AS400 object and connects to
|
||
|
the record-level access service.</li>
|
||
|
<li id="rlaex1__dup0014"><a name="rlaex1__dup0014"><!-- --></a>This line creates a QSYSObjectPathName object that obtains
|
||
|
the integrated file system path name form of the object to be displayed.</li>
|
||
|
<li id="rlaex1__dup0015"><a name="rlaex1__dup0015"><!-- --></a>This statement creates an object that represents an existing
|
||
|
sequential file on the server you are connected to. This sequential file
|
||
|
is the file that will be displayed.</li>
|
||
|
<li id="rlaex1__dup0016"><a name="rlaex1__dup0016"><!-- --></a>These lines retrieve the record format of the file.</li>
|
||
|
<li id="rlaex1__dup0017"><a name="rlaex1__dup0017"><!-- --></a>This line sets the record format for the file.</li>
|
||
|
<li id="rlaex1__dup0018"><a name="rlaex1__dup0018"><!-- --></a>This line opens the selected file for reading. It will read
|
||
|
100 records at a time, when it is possible.</li>
|
||
|
<li id="rlaex1__dup0019"><a name="rlaex1__dup0019"><!-- --></a>This line of code reads each record in sequence.</li>
|
||
|
<li id="rlaex1__eight"><a name="rlaex1__eight"><!-- --></a>This line closes the file.</li>
|
||
|
<li id="rlaex1__nine"><a name="rlaex1__nine"><!-- --></a>This line disconnects from the record-level access service.</li>
|
||
|
</ol>
|
||
|
<p>[ <a href="rlaex2.htm#rlaex2">Next part</a> ]</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|