118 lines
4.9 KiB
HTML
118 lines
4.9 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 2 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="rlaex2" />
|
||
|
<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 2 of 2)</title>
|
||
|
</head>
|
||
|
<body id="rlaex2"><a name="rlaex2"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">Example: Using record-level access (part 2 of 2)</h1>
|
||
|
<div><p></p>
|
||
|
<div class="section"><p>[ <a href="rlaex1.htm#rlaex1">Previous 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.
|
||
|
//
|
||
|
// Calling syntax: java RLACreateExample
|
||
|
//
|
||
|
//////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.util.*;
|
||
|
import com.ibm.as400.access.*;
|
||
|
|
||
|
public class RLACreateExample
|
||
|
{
|
||
|
public static void main(String[] args)
|
||
|
{
|
||
|
AS400 system = new AS400(args[0]);
|
||
|
String filePathName = "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/MBR1.MBR"; <a href="#rlaex2__dup0020">Note 1 </a>
|
||
|
|
||
|
try
|
||
|
{
|
||
|
SequentialFile theFile = new SequentialFile(system, filePathName);
|
||
|
|
||
|
// Begin Note Two
|
||
|
CharacterFieldDescription lastNameField =
|
||
|
new CharacterFieldDescription(new AS400Text(20), "LNAME");
|
||
|
CharacterFieldDescription firstNameField =
|
||
|
new CharacterFieldDescription(new AS400Text(20), "FNAME");
|
||
|
BinaryFieldDescription yearsOld =
|
||
|
new BinaryFieldDescription(new AS400Bin4(), "AGE");
|
||
|
|
||
|
RecordFormat fileFormat = new RecordFormat("RF");
|
||
|
fileFormat.addFieldDescription(lastNameField);
|
||
|
fileFormat.addFieldDescription(firstNameField);
|
||
|
fileFormat.addFieldDescription(yearsOld);
|
||
|
|
||
|
theFile.create(fileFormat, "A file of names and ages"); <a href="#rlaex2__dup0021">Note 2 </a>
|
||
|
// End Note Two
|
||
|
|
||
|
|
||
|
theFile.open(AS400File.READ_WRITE, 1, AS400File.COMMIT_LOCK_LEVEL_NONE);
|
||
|
|
||
|
// Begin Note Three
|
||
|
Record newData = fileFormat.getNewRecord();
|
||
|
newData.setField("LNAME", "Doe");
|
||
|
newData.setField("FNAME", "John");
|
||
|
newData.setField("AGE", new Integer(63));
|
||
|
|
||
|
theFile.write(newData); <a href="#rlaex2__dup0022">Note 3 </a>
|
||
|
// End Note Three
|
||
|
|
||
|
theFile.close();
|
||
|
}
|
||
|
catch(Exception e)
|
||
|
{
|
||
|
System.out.println("An error has occurred: ");
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
system.disconnectService(AS400.RECORDACCESS);
|
||
|
|
||
|
System.exit(0);
|
||
|
}
|
||
|
}</pre>
|
||
|
</div>
|
||
|
<div class="section"><ol><li id="rlaex2__dup0020"><a name="rlaex2__dup0020"><!-- --></a>(args[0]) in the previous line and MYFILE.FILE are pieces
|
||
|
of code that are prerequisites for the rest of the example to run. The program
|
||
|
assumes that the library MYLIB exists on the server and that the user has
|
||
|
access to it.</li>
|
||
|
<li id="rlaex2__dup0021"><a name="rlaex2__dup0021"><!-- --></a>The text within the Java™ comments labeled "Begin Note Two" and
|
||
|
"End Note Two" shows how to create a record format yourself instead of getting
|
||
|
the record format from an existing file. The last line in this block creates
|
||
|
the file on the server.</li>
|
||
|
<li id="rlaex2__dup0022"><a name="rlaex2__dup0022"><!-- --></a>The text within the Java comments labeled "Begin Note Three"
|
||
|
and "End Note Three" shows a way to create a record and then write it to a
|
||
|
file.</li>
|
||
|
</ol>
|
||
|
<p>[ <a href="rlaex1.htm#rlaex1">Previous part</a> ]</p>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|