ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaha_5.4.0.1/sampthrd.htm

784 lines
38 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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: JAAS SampleThreadSubjectLogin" />
<meta name="DC.Relation" scheme="URI" content="codedisclaimer.htm" />
<meta name="DC.Relation" scheme="URI" content="codeex.htm" />
<meta name="DC.Relation" scheme="URI" content="intdatex.htm" />
<meta name="DC.Relation" scheme="URI" content="intnumex.htm" />
<meta name="DC.Relation" scheme="URI" content="intlocex.htm" />
<meta name="DC.Relation" scheme="URI" content="accesspropertytest.htm" />
<meta name="DC.Relation" scheme="URI" content="putgetblobs.htm" />
<meta name="DC.Relation" scheme="URI" content="callex.htm" />
<meta name="DC.Relation" scheme="URI" content="usingpositioneddelete.htm" />
<meta name="DC.Relation" scheme="URI" content="putgetclobs.htm" />
<meta name="DC.Relation" scheme="URI" content="udbdatasourcebind.htm" />
<meta name="DC.Relation" scheme="URI" content="udbdatasourceuse2.htm" />
<meta name="DC.Relation" scheme="URI" content="udbdatasourcebind2.htm" />
<meta name="DC.Relation" scheme="URI" content="dataex.htm" />
<meta name="DC.Relation" scheme="URI" content="udbdatasourcebind.htm" />
<meta name="DC.Relation" scheme="URI" content="putgetdatalinks.htm" />
<meta name="DC.Relation" scheme="URI" content="distinct.htm" />
<meta name="DC.Relation" scheme="URI" content="sqljex.htm" />
<meta name="DC.Relation" scheme="URI" content="jtatxend.htm" />
<meta name="DC.Relation" scheme="URI" content="invalidconnect.htm" />
<meta name="DC.Relation" scheme="URI" content="basicjdbc.htm" />
<meta name="DC.Relation" scheme="URI" content="jtamulticonn.htm" />
<meta name="DC.Relation" scheme="URI" content="udbdatasourceuse.htm" />
<meta name="DC.Relation" scheme="URI" content="pmd.htm" />
<meta name="DC.Relation" scheme="URI" content="usingpositionedupdate.htm" />
<meta name="DC.Relation" scheme="URI" content="resultex.htm" />
<meta name="DC.Relation" scheme="URI" content="sensitive2.htm" />
<meta name="DC.Relation" scheme="URI" content="sensitive.htm" />
<meta name="DC.Relation" scheme="URI" content="connectionpoolingsetup.htm" />
<meta name="DC.Relation" scheme="URI" content="exceptionexample.htm" />
<meta name="DC.Relation" scheme="URI" content="jtatxsuspend.htm" />
<meta name="DC.Relation" scheme="URI" content="jtatxeffect.htm" />
<meta name="DC.Relation" scheme="URI" content="connectionpoolingtest.htm" />
<meta name="DC.Relation" scheme="URI" content="statementpoolingtest.htm" />
<meta name="DC.Relation" scheme="URI" content="updateblobs.htm" />
<meta name="DC.Relation" scheme="URI" content="updateclobs.htm" />
<meta name="DC.Relation" scheme="URI" content="jtamultitx.htm" />
<meta name="DC.Relation" scheme="URI" content="useblobs.htm" />
<meta name="DC.Relation" scheme="URI" content="useclobs.htm" />
<meta name="DC.Relation" scheme="URI" content="jtacommit.htm" />
<meta name="DC.Relation" scheme="URI" content="safegetudts.htm" />
<meta name="DC.Relation" scheme="URI" content="getconnections.htm" />
<meta name="DC.Relation" scheme="URI" content="prepex.htm" />
<meta name="DC.Relation" scheme="URI" content="crdb2cac.htm" />
<meta name="DC.Relation" scheme="URI" content="stateex.htm" />
<meta name="DC.Relation" scheme="URI" content="jaaswrld.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahajgsssrcl.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahajgsssrsr.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahajgssjacl.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahajgssjasr.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahajsseexmpls.htm" />
<meta name="DC.Relation" scheme="URI" content="callclex.htm" />
<meta name="DC.Relation" scheme="URI" content="clcommex.htm" />
<meta name="DC.Relation" scheme="URI" content="jvlngex1.htm" />
<meta name="DC.Relation" scheme="URI" content="callcex.htm" />
<meta name="DC.Relation" scheme="URI" content="calrpgex.htm" />
<meta name="DC.Relation" scheme="URI" content="iostrmex.htm" />
<meta name="DC.Relation" scheme="URI" content="invapiex.htm" />
<meta name="DC.Relation" scheme="URI" content="rzahapaseexmpls.htm" />
<meta name="DC.Relation" scheme="URI" content="jniex.htm" />
<meta name="DC.Relation" scheme="URI" content="socketex.htm" />
<meta name="DC.Relation" scheme="URI" content="runjpdex.htm" />
<meta name="DC.Relation" scheme="URI" content="sqljex.htm" />
<meta name="DC.Relation" scheme="URI" content="sslcex01.htm" />
<meta name="DC.Relation" scheme="URI" content="sslcex03.htm" />
<meta name="DC.Relation" scheme="URI" content="sslcex02.htm" />
<meta name="DC.Relation" scheme="URI" content="sslcex04.htm" />
<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="sampthrd" />
<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: JAAS SampleThreadSubjectLogin</title>
</head>
<body id="sampthrd"><a name="sampthrd"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: JAAS SampleThreadSubjectLogin</h1>
<div><div class="section"><p>This example shows you the implementation of the SampleThreadSubjectLogin
class.</p>
<div class="note"><span class="notetitle">Note:</span> By using the code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre>//////////////////////////////////////////////////////////////////////
//
// 5722-JV1
// (C) Copyright IBM Corp. 2000
//
//////////////////////////////////////////////////////////////////////
//
// File Name: SampleThreadSubjectLogin.java
//
// Class: SampleThreadSubjectLogin
//
/////////////////////////////////////////////////////////////////////
//
// CHANGE ACTIVITY:
//
//
// END CHANGE ACTIVITY
//
////////////////////////////////////////////////////////////////////
import com.ibm.security.auth.ThreadSubject;
import com.ibm.as400.access.*;
import java.io.*;
import java.util.*;
import java.security.Principal;
import javax.security.auth.*;
import javax.security.auth.callback.*;
import javax.security.auth.login.*;
/**
* This SampleThreadSubjectLogin application authenticates a single
* user, swaps the OS thread identity to the authenticated user,
* and then writes "Hello World" into a privately authorized
* file, thread.txt, in the user's test directory.
*
* The user is requested to enter the user id and password to
* authenticate.
*
* If successful, the user name and number of Credentials
* are displayed.
*
*
Setup and run instructions:
1) Create a new user, JAAS13, by invoking
"CRTUSRPRF USRPRF(JAAS13) PASSWORD() TEXT('JAAS sample user id')"
with *USER class authority.
2) Allocate a dummy test file, "<strong>yourTestDir</strong>/thread.txt", and
privately grant JAAS13 *RWX authority to it for write access.
3) Copy SampleThreadSubjectLogin.java into your test directory.
4) Change the current directory to your test directory and compile the
java source code.
Enter -
strqsh
cd '<strong>yourTestDir</strong>'
javac -J-Djava.version=1.3
-classpath /qibm/proddata/os400/java400/ext/jaas13.jar:
/QIBM/ProdData/HTTP/Public/jt400/lib/jt400.jar:.
-d ./classes
*.java
5) Copy threadLogin.config, threadJaas.policy, and threadJava2.policy
into your test directory.
6) If not already done, add the symbolic link to the extension
directory for the jaas13.jar file.
The extension class loader should normally load the JAR file.
ADDLNK OBJ('/QIBM/ProdData/OS400/Java400/ext/jaas13.jar')
NEWLNK('/QIBM/ProdData/Java400/jdk13/lib/ext/jaas13.jar')
7) If not already done to run this sample, add the symbolic link to the extension
directory for the jt400.jar and jt400ntv.jar files. This causes these
files to be loaded by the extension class loader. The application class loader
can also load these files by including them in the CLASSPATH.
If these files are loaded from the class path directory,
do not add the symbolic link to the extension directory.
The jaas13.jar file requires these JAR files for the credential
implementation classes which are part of the IBM Toolbox
for Java (5722-JC1) Licensed Program Product.
(See the IBM Toolbox for Java topic for documentation
on the credential classes found in the left frame
under Security Classes =&gt; Authentication. Select the link to the
ProfileTokenCredential class. At the top select 'This Package' for the
entire com/ibm/as400/security/auth Java package. Javadoc for the
authentication classes can also be found by selecting 'Javadoc' =&gt;
'Access Classes' on the left frame. Select 'All Packages' at the top
and look for the com.ibm.as400.security.* packages)
ADDLNK OBJ('/QIBM/ProdData/HTTP/Public/jt400/lib/jt400.jar')
NEWLNK('/QIBM/ProdData/Java400/jdk13/lib/ext/jt400.jar')
ADDLNK OBJ('/QIBM/ProdData/OS400/jt400/lib/jt400Native.jar')
NEWLNK('/QIBM/ProdData/Java400/jdk13/lib/ext/jt400Native.jar')
/////////////////////////////////////
IMPORTANT NOTES -
/////////////////////////////////////
When updating the Java2 policy files
for a real application remember to grant the
appropriate permissions to the actual locations of the IBM Toolbox
for Java JAR files. Even though they are symbolically linked to
the extension directories previously listed which are granted
java.security.AllPermission in the
${java.home}/lib/security/java.policy file, authorization is based on
the actual location of the JAR files.
For example, to successfully use the credential classes
in IBM Toolbox for Java, you would add the below to your application's
Java2 policy file -
grant codeBase "file:/QIBM/ProdData/HTTP/Public/jt400/lib/jt400.jar"
{
permission javax.security.auth.AuthPermission "modifyThreadIdentity";
permission java.lang.RuntimePermission "loadLibrary.*";
permission java.lang.RuntimePermission "writeFileDescriptor";
permission java.lang.RuntimePermission "readFileDescriptor";
}
You also need to add these permissions for the application's
codeBase since the operations performed by the IBM Toolbox
for Java JAR files do not run in privileged mode.
This sample already grants these permissions to all java classes by
omitting the codeBase parameter in the threadJava2.policy file.
8) Make sure the Host Servers are started and running.
The ProfileTokenCredential classes which reside in IBM Toolbox for Java,
i.e. jt400.jar, are used as the credentials that are attached
to the authenticated subject by the SampleThreadSubjectLogin.java
program. The IBM Toolbox for Java credential classes require access
to the Host Servers.
9) Invoke SampleThreadSubjectLogin while signed on as a user that
does not have access to '<strong>yourTestDir</strong>/thread.txt'.
10) Start the sample by entering the following CL commands =&gt;
CHGCURDIR DIR('<strong>yourTestDir</strong>')
JAVA CLASS(SampleThreadSubjectLogin)
CLASSPATH('<strong>yourTestDir</strong>/classes')
PROP((java.version '1.3')
(java.security.manager)
(java.security.auth.login.config
'<strong>yourTestDir</strong>/threadLogin.config')
(java.security.policy
'<strong>yourTestDir</strong>/threadJava2.policy')
(java.security.auth.policy
'<strong>yourTestDir</strong>/threadJaas.policy'))
Enter the user id and password when prompted from step 1.
11) Check <strong>yourTestDir</strong>/thread.txt for the "Hello World" entry.
*
**/
public class SampleThreadSubjectLogin {
/**
* Attempt to authenticate the user.
*
* @param args
* Input arguments for this application (ignored).
*
*/
public static void main(String[] args) {
// use the configured LoginModules for the "AS400ToolboxApp" entry
LoginContext lc = null;
try {
// if provided, the same subject is used for multiple login attempts
lc = new LoginContext("AS400ToolboxApp",
new Subject(),
new SampleCBHandler());
} catch (LoginException le) {
le.printStackTrace();
System.exit(-1);
}
// the user has 3 attempts to authenticate successfully
int i;
for (i = 0; i &lt; 3; i++) {
try {
// attempt authentication
lc.login();
// if we return with no exception, authentication succeeded
break;
} catch (AccountExpiredException aee) {
System.out.println("Your account has expired");
System.exit(-1);
} catch (CredentialExpiredException cee) {
System.out.println("Your credentials have expired.");
System.exit(-1);
} catch (FailedLoginException fle) {
System.out.println("Authentication Failed");
try {
Thread.currentThread().sleep(3000);
} catch (Exception e) {
// ignore
}
} catch (Exception e) {
System.out.println("Unexpected Exception - unable to continue");
e.printStackTrace();
System.exit(-1);
}
}
// did they fail three times?
if (i == 3) {
System.out.println("Sorry authentication failed");
System.exit(-1);
}
// display authenticated principals &amp; credentials
System.out.println("Authentication Succeeded");
System.out.println("Principals:");
Iterator itr = lc.getSubject().getPrincipals().iterator();
while (itr.hasNext())
System.out.println(itr.next());
itr = lc.getSubject().getPrivateCredentials().iterator();
while (itr.hasNext())
System.out.println(itr.next());
itr = lc.getSubject().getPublicCredentials().iterator();
while (itr.hasNext())
System.out.println(itr.next());
// let's do some Principal-based work:
ThreadSubject.doAsPrivileged(lc.getSubject(), new java.security.PrivilegedAction() {
public Object run() {
System.out.println("\nYour java.home property: "
+System.getProperty("java.home"));
System.out.println("\nYour user.home property: "
+System.getProperty("user.home"));
File f = new File("thread.txt");
System.out.print("\nthread.txt does ");
if (!f.exists()) System.out.print("not ");
System.out.println("exist in your current directory");
try {
// write "Hello World number x" into thread.txt
PrintStream ps = new PrintStream(new FileOutputStream("thread.txt", true), true);
long flen = f.length();
ps.println("Hello World number " +
Long.toString(flen/22) +
"\n");
ps.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\nOh, by the way, " + SampleThreadSubjectLogin.getCurrentUser());
try {
Thread.currentThread().sleep(2000);
} catch (Exception e) {
// ignore
}
System.out.println("\n\nHello World!\n");
return null;
}
}, null);
System.exit(0);
}// end main()
// Returns the current OS identity for the main thread of the application.
// (This routine uses classes from IBM Toolbox for Java)
// Note - Applications running on a secondary thread cannot use this API to determine the current user.
static public String getCurrentUser() {
try {
AS400 localSys = new AS400("localhost", "*CURRENT", "*CURRENT");
int ccsid = localSys.getCcsid();
ProgramCall qusrjobi = new ProgramCall(localSys);
ProgramParameter[] parms = new ProgramParameter[6];
int rLength = 100;
parms[0] = new ProgramParameter(rLength);
parms[1] = new ProgramParameter(new AS400Bin4().toBytes(rLength));
parms[2] = new ProgramParameter(new AS400Text(8, ccsid, localSys).toBytes("JOBI0600"));
parms[3] = new ProgramParameter(new AS400Text(26,ccsid, localSys).toBytes("*"));
parms[4] = new ProgramParameter(new AS400Text(16,ccsid, localSys).toBytes(""));
parms[5] = new ProgramParameter(new AS400Bin4().toBytes(0));
qusrjobi.setProgram(QSYSObjectPathName.toPath("QSYS", "QUSRJOBI", "PGM"), parms);
AS400Text uidText = new AS400Text(10, ccsid, localSys);
// Invoke the QUSRJOBI API
qusrjobi.run();
byte[] uidBytes = new byte[10];
System.arraycopy((qusrjobi.getParameterList())[0].getOutputData(), 90, uidBytes, 0, 10);
return ((String)(uidText.toObject(uidBytes))).trim();
}
catch (Exception e) {
e.printStackTrace();
}
return "";
}
} //end SampleThreadSubjectLogin class
/**
* A CallbackHandler is passed to underlying security
* services so that they may interact with the application
* to retrieve specific authentication data,
* such as user names and passwords, or to display certain
* information, such as error and warning messages.
*
* CallbackHandlers are implemented in an application
* and platform-dependent fashion. The implementation decides
* how to retrieve and display information depending on the
* Callbacks passed to it.
*
* This class provides a sample CallbackHandler for applications
* running in an <span class="keyword">i5/OS™</span> environment. However, it is not intended
* to fulfill the requirements of production applications.
* As indicated, the CallbackHandler is ultimately considered to
* be application-dependent, as individual applications have
* unique error checking, data handling, and user
* interface requirements.
*
* The following callbacks are handled:
* </pre>
<ul><li>*</li>
<li>NameCallback *</li>
<li>PasswordCallback *</li>
<li>TextOutputCallback *</li>
</ul>
<pre> *
* For simplicity, prompting is handled interactively through
* standard input and output. However, it is worth noting
* that when standard input is provided by the console, this
* approach allows passwords to be viewed as they are
* typed. This should be avoided in production
* applications.
*
* This CallbackHandler also allows a name and password
* to be acquired through an alternative mechanism
* and set directly on the handler to bypass the need for
* user interaction on the respective Callbacks.
*
*/
class SampleCBHandler implements CallbackHandler {
private String name_ = null;
private String password_ = null;
/**
* Constructs a new SampleCBHandler.
*
*/
public SampleCBHandler() {
this(null, null);
}
/**
* Constructs a new SampleCBHandler.
*
* A name and password can optionally be specified in
* order to bypass the need to prompt for information
* on the respective Callbacks.
*
* @param name
* The default value for name callbacks. A null
* value indicates that the user should be
* prompted for this information. A non-null value
* cannot be zero length or exceed 10 characters.
*
* @param password
* The default value for password callbacks. A null
* value indicates that the user should be
* prompted for this information. A non-null value
* cannot be zero length or exceed 10 characters.
*/
public SampleCBHandler(String name, String password) {
if (name != null)
if ((name.length()==0) || (name.length()&gt;10))
throw new IllegalArgumentException("name");
name_ = name;
if (password != null)
if ((password.length()==0) || (password.length()&gt;10))
throw new IllegalArgumentException("password");
password_ = password;
}
/**
* Handle the given name callback.
*
* First check to see if a name has been passed in
* on the constructor. If so, assign it to the
* callback and bypass the prompt.
*
* If a value has not been preset, attempt to prompt
* for the name using standard input and output.
*
* @param c
* The NameCallback.
*
* @exception java.io.IOException
* If an input or output error occurs.
*
*/
private void handleNameCallback(NameCallback c) throws IOException {
// Check for cached value
if (name_ != null) {
c.setName(name_);
return;
}
// No preset value; attempt stdin/out
c.setName(
stdIOReadName(c.getPrompt(), 10));
}
/**
* Handle the given name callback.
*
* First check to see if a password has been passed
* in on the constructor. If so, assign it to the
* callback and bypass the prompt.
*
* If a value has not been preset, attempt to prompt
* for the password using standard input and output.
*
* @param c
* The PasswordCallback.
*
* @exception java.io.IOException
* If an input or output error occurs.
*
*/
private void handlePasswordCallback(PasswordCallback c) throws IOException {
// Check for cached value
if (password_ != null) {
c.setPassword(password_.toCharArray());
return;
}
// No preset value; attempt stdin/out
// Note - Not for production use.
// Password is not concealed by standard console I/O
if (c.isEchoOn())
c.setPassword(
stdIOReadName(c.getPrompt(), 10).toCharArray());
else
{
// Note - Password is not concealed by standard console I/O
c.setPassword(stdIOReadName(c.getPrompt(), 10).toCharArray());
}
}
/**
* Handle the given text output callback.
*
* If the text is informational or a warning,
* text is written to standard output. If the
* callback defines an error message, text is
* written to standard error.
*
* @param c
* The TextOutputCallback.
*
* @exception java.io.IOException
* If an input or output error occurs.
*
*/
private void handleTextOutputCallback(TextOutputCallback c) throws IOException {
if (c.getMessageType() == TextOutputCallback.ERROR)
System.err.println(c.getMessage());
else
System.out.println(c.getMessage());
}
/**
* Retrieve or display the information requested in the
* provided Callbacks.
*
* The <em>handle</em> method implementation
* checks the instance(s) of the <samp class="codeph">Callback</samp>
* object(s) passed in to retrieve or display the
* requested information.
*
* @param callbacks
* An array of <samp class="codeph">Callback</samp> objects provided
* by an underlying security service which contains
* the information requested to be retrieved or displayed.
*
* @exception java.io.IOException
* If an input or output error occurs.
*
* @exception UnsupportedCallbackException
* If the implementation of this method does not support
* one or more of the Callbacks specified in the
* <samp class="codeph">callbacks</samp> parameter.
*
*/
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException
{
for (int i=0; i&lt;callbacks.length; i++) {
Callback c = callbacks[i];
if (c instanceof NameCallback)
handleNameCallback((NameCallback)c);
else if (c instanceof PasswordCallback)
handlePasswordCallback((PasswordCallback)c);
else if (c instanceof TextOutputCallback)
handleTextOutputCallback((TextOutputCallback)c);
else
throw new UnsupportedCallbackException
(callbacks[i]);
}
}
/**
* Displays the given string using standard output,
* followed by a space to separate from subsequent
* input.
*
* @param prompt
* The text to display.
*
* @exception IOException
* If an input or output error occurs.
*
*/
private void stdIOPrompt(String prompt) throws IOException {
System.out.print(prompt + ' ');
System.out.flush();
}
/**
* Reads a String from standard input, stopped at
* <em>maxLength</em> or by a newline.
*
* @param prompt
* The text to display to standard output immediately
* prior to reading the requested value.
*
* @param maxLength
* Maximum length of the String to return.
*
* @return
* The entered string. The value returned does
* not contain leading or trailing whitespace
* and is converted to uppercase.
*
* @exception IOException
* If an input or output error occurs.
*
*/
private String stdIOReadName(String prompt, int maxLength) throws IOException {
stdIOPrompt(prompt);
String s =
(new BufferedReader
(new InputStreamReader(System.in))).readLine().trim();
if (s.length() &lt; maxLength)
s = s.substring(0,maxLength);
return s.toUpperCase();
}
}//end SampleCBHandler class</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="codeex.htm" title="The following is a list of code examples for the IBM Developer Kit for Java.">Code examples for the IBM Developer Kit for Java</a></div>
</div>
<div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="rzahapaseexmpls.htm" title="The IBM i5/OS PASE native method for Java example calls an instance of a native C method that then uses Java Native Interface (JNI) to call back into Java code. Rather than accessing the string directly from Java code, the example calls a native method that then calls back into Java through JNI to get the string value.">Example: IBM i5/OS PASE native method for Java</a></div>
</div>
<div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="runjpdex.htm" title="You can either use the iSeries command line or the Qshell environment to run the Java Performance Data Converter (JPDC).">Example: Run the Java Performance Data Converter</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="intdatex.htm" title="This example shows how you can use locales to format dates.">Example: Internationalization of dates using the java.util.DateFormat class</a></div>
<div><a href="intnumex.htm" title="This example shows how you can use locales to format numbers.">Example: Internationalization of numeric display using the java.util.NumberFormat class</a></div>
<div><a href="intlocex.htm" title="This example shows how you can use locales with resource bundles to internationalize program strings.">Example: Internationalization of locale-specific data using the java.util.ResourceBundle class</a></div>
<div><a href="accesspropertytest.htm" title="This is an example of how to use the Access property.">Example: Access property</a></div>
<div><a href="putgetblobs.htm" title="This is an example of how a BLOB can be put into the database or retrieved from the database.">Example: BLOB</a></div>
<div><a href="callex.htm" title="This is an example of how to use the CallableStatement interface.">Example: CallableStatement interface for IBM Developer Kit for Java</a></div>
<div><a href="usingpositioneddelete.htm" title="This is an example of how to remove values from a table through another statement's cursor.">Example: Remove values from a table through another statement's cursor</a></div>
<div><a href="putgetclobs.htm" title="This is an example of how a CLOB can be put into the database or retrieved from the database.">Example: CLOB</a></div>
<div><a href="udbdatasourcebind.htm" title="This is an example of how to create a UDBDataSource and get it bound with JNDI.">Example: Create a UDBDataSource and bind it with JNDI</a></div>
<div><a href="udbdatasourceuse2.htm" title="This is an example of how to create a UDBDataSource, and use the getConnection method to obtain a user ID and password at runtime.">Example: Create a UDBDataSource, and obtain a user ID and password</a></div>
<div><a href="udbdatasourcebind2.htm" title="This is an example of how to create a UDBDataSource, and set the user ID and password as DataSource properties.">Example: Create a UDBDataSourceBind and set DataSource properties</a></div>
<div><a href="dataex.htm" title="This example shows how to return a list of tables.">Example: DatabaseMetaData interface for IBM Developer Kit for Java - Return a list of tables</a></div>
<div><a href="putgetdatalinks.htm" title="This is an example of how to use datalinks in your applications.">Example: Datalink</a></div>
<div><a href="distinct.htm" title="This is an example of how to use distinct types.">Example: Distinct types</a></div>
<div><a href="sqljex.htm" title="The following example SQLJ application, App.sqlj, uses static SQL to retrieve and update data from the EMPLOYEE table of the DB2 sample database.">Example: Embed SQL Statements in your Java application</a></div>
<div><a href="jtatxend.htm" title="This is an example of ending a transaction in your application.">Example: End a transaction</a></div>
<div><a href="invalidconnect.htm" title="This is an example of how to use the Connection property in SQL naming mode.">Example: Invalid user ID and password</a></div>
<div><a href="basicjdbc.htm" title="This is an example of how to use the BasicJDBC program.">Example: JDBC</a></div>
<div><a href="jtamulticonn.htm" title="This is an example of how to use multiple connections working on a single transaction.">Example: Multiple connections that work on a transaction</a></div>
<div><a href="udbdatasourceuse.htm" title="The following example obtains an initial context before binding the UDBDataSource. The lookup method is then used on that context to return an object of type DataSource for the application to use.">Example: Obtain an initial context before binding UDBDataSource</a></div>
<div><a href="pmd.htm" title="This is an example of using the ParameterMetaData interface to retrieve information about parameters.">Example: ParameterMetaData</a></div>
<div><a href="usingpositionedupdate.htm" title="This is an example of how to change values with a statement through another statement's cursor.">Example: Change values with a statement through another statement's cursor</a></div>
<div><a href="resultex.htm" title="This is an example of how to use the ResultSet interface.">Example: ResultSet interface for IBM Developer Kit for Java</a></div>
<div><a href="sensitive2.htm" title="The following example shows how a change can affect a where clause of an SQL statement based on the sensitivity of the ResultSet.">Example: ResultSet sensitivity</a></div>
<div><a href="sensitive.htm" title="The following example shows the difference between sensitive and insensitive ResultSets when rows are inserted into a table.">Example: Sensitive and insensitive ResultSets</a></div>
<div><a href="connectionpoolingsetup.htm" title="This is an example of how to use connection pooling with UDBDataSource and UDBConnectionPoolDataSource.">Example: Set up connection pooling with UDBDataSource and UDBConnectionPoolDataSource</a></div>
<div><a href="exceptionexample.htm" title="This is an example of catching an SQLException and dumping all the information that it provides.">Example: SQLException</a></div>
<div><a href="jtatxsuspend.htm" title="This is an example of a transaction that is suspended and then is resumed.">Example: Suspend and resume a transaction</a></div>
<div><a href="jtatxeffect.htm" title="This is an example of the how a Statement object is reprocessed under another transaction to perform work.">Example: Suspended ResultSets</a></div>
<div><a href="connectionpoolingtest.htm" title="This is an example of how to test the performance of the pooling example against the performance of the non-pooling example.">Example: Test the performance of connection pooling</a></div>
<div><a href="statementpoolingtest.htm" title="This is an example of testing one DataSource that uses connection pooling only and the other DataSource that uses statement and connection pooling.">Example: Test the performance of two DataSources</a></div>
<div><a href="updateblobs.htm" title="This is an example of how to update BLOBs in your applications.">Example: Update BLOBs</a></div>
<div><a href="updateclobs.htm" title="This is an example of how to update CLOBs in your applications.">Example: Update CLOBs</a></div>
<div><a href="jtamultitx.htm" title="This is an example of how to use a single connection with multiple transactions.">Example: Use a connection with multiple transactions</a></div>
<div><a href="useblobs.htm" title="This is an example of how to use BLOBs in your applications.">Example: Use BLOBs</a></div>
<div><a href="useclobs.htm" title="This is an example of how to use CLOBs in your applications.">Example: Use CLOBs</a></div>
<div><a href="jtacommit.htm" title="This is an example of how to use the Java Transaction API (JTA) to handle a transaction in an application.">Example: Use JTA to handle a transaction</a></div>
<div><a href="safegetudts.htm" title="This is an example of how to use metadata ResultSets that have more than one column.">Example: Use metadata ResultSets that have more than one column</a></div>
<div><a href="getconnections.htm" title="This is an example of how to use the native JDBC connection and the IBM Toolbox for Java JDBC connection in a program.">Example: Use native JDBC and IBM Toolbox for Java JDBC concurrently</a></div>
<div><a href="prepex.htm" title="This is an example of using a PreparedStatement object's executeQuery method to obtain a ResultSet.">Example: Use PreparedStatement to obtain a ResultSet</a></div>
<div><a href="crdb2cac.htm" title="There are several ways to place data into a DB2CachedRowSet.">Create and populate a DB2CachedRowSet</a></div>
<div><a href="stateex.htm" title="This is an example of how to use the Statement object's executeUpdate method.">Example: Use the Statement object's executeUpdate method</a></div>
<div><a href="jaaswrld.htm" title="These examples show you the three files that are needed to compile and run HelloWorld for JAAS.">Examples: JAAS HelloWorld</a></div>
<div><a href="rzahajgsssrcl.htm">Sample: IBM JGSS non-JAAS client program</a></div>
<div><a href="rzahajgsssrsr.htm">Sample: IBM JGSS non-JAAS server program</a></div>
<div><a href="rzahajgssjacl.htm">Sample: IBM JGSS JAAS-enabled client program</a></div>
<div><a href="rzahajgssjasr.htm">Sample: IBM JGSS JAAS-enabled server program</a></div>
<div><a href="rzahajsseexmpls.htm" title="The JSSE examples show how a client and a server can use the native iSeries JSSE provider to create a context that enables secure communications.">Examples: IBM Java Secure Sockets Extension</a></div>
<div><a href="callclex.htm" title="This example shows how to run CL programs from within a Java program. In this example, the Java class CallCLPgm runs a CL program.">Example: Call a CL program with java.lang.Runtime.exec()</a></div>
<div><a href="clcommex.htm" title="This example shows how to run a control language (CL) command from within a Java program.">Example: Call a CL command with java.lang.Runtime.exec()</a></div>
<div><a href="jvlngex1.htm" title="This example shows how to call another Java program with java.lang.Runtime.exec(). This class calls the Hello program that is shipped as part of the IBM Developer Kit for Java. When the Hello class writes to System.out, this program gets a handle to the stream and can read from it.">Example: Call another Java program with java.lang.Runtime.exec()</a></div>
<div><a href="callcex.htm" title="This is an example of a C program that uses the system() function to call the Java Hello program.">Example: Call Java from C</a></div>
<div><a href="calrpgex.htm" title="This is an example of an RPG program that uses the QCMDEXC API to call the Java Hello program.">Example: Call Java from RPG</a></div>
<div><a href="iostrmex.htm" title="This example shows how to call a C program from Java and use input and output streams for interprocess communication.">Example: Use input and output streams for interprocess communication</a></div>
<div><a href="invapiex.htm" title="This example follows the standard Invocation API paradigm.">Example: Java Invocation API</a></div>
<div><a href="jniex.htm" title="This example program is a simple Java Native Interface (JNI) example in which a C native method is used to display &#34;Hello, World.&#34; Use the javah tool with the NativeHello class file to generate the NativeHello.h file. This example assumes that the NativeHello C implementation is part of a service program that is called NATHELLO.">Examples: Use the Java Native Interface for native methods</a></div>
<div><a href="socketex.htm" title="This example uses sockets to communicate between a Java program and a C program.">Example: Use sockets for interprocess communication</a></div>
<div><a href="sslcex01.htm" title="These examples show you how to change a simple socket class, named simpleSocketClient, so that it uses socket factories to create all of the sockets. The first example shows you the simpleSocketClient class without socket factories. The second example shows you the simpleSocketClient class with socket factories. In the second example, simpleSocketClient is renamed to factorySocketClient.">Examples: Change your Java code to use client socket factories</a></div>
<div><a href="sslcex03.htm" title="These examples show you how to change a simple socket class, named simpleSocketServer, so that it uses socket factories to create all of the sockets. The first example shows you the simpleSocketServer class without socket factories. The second example shows you the simpleSocketServer class with socket factories. In the second example, simpleSocketServer is renamed to factorySocketServer.">Examples: Change your Java code to use server socket factories</a></div>
<div><a href="sslcex02.htm" title="These examples show you how to change one class, named factorySocketClient, to use secure sockets layer (SSL). The first example shows you the factorySocketClient class not using SSL. The second example shows you the same class, renamed factorySSLSocketClient, using SSL.">Examples: Change your Java client to use secure sockets layer</a></div>
<div><a href="sslcex04.htm" title="These examples show you how to change one class, named factorySocketServer, to use secure sockets layer (SSL).">Examples: Change your Java server to use secure sockets layer</a></div>
</div>
<div class="linklist"><strong>Collected links</strong><br />
<div><a href="codedisclaimer.htm">Code example disclaimer</a></div></div>
</div>
</body>
</html>