149 lines
8.6 KiB
HTML
149 lines
8.6 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="task" />
|
|
<meta name="DC.Title" content="JDBC tutorial" />
|
|
<meta name="abstract" content="The following is a tutorial on writing a Java Database Connectivity (JDBC) program and having it run on the an iSeries server with the native JDBC driver. It is designed to show you the basic steps required for your program to run JDBC." />
|
|
<meta name="description" content="The following is a tutorial on writing a Java Database Connectivity (JDBC) program and having it run on the an iSeries server with the native JDBC driver. It is designed to show you the basic steps required for your program to run JDBC." />
|
|
<meta name="DC.Relation" scheme="URI" content="jdbcgets.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="jdbctydr.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="jdbcreqs.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="dasrjndi.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="basicjdbc.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="jdbctutr" />
|
|
<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>JDBC tutorial</title>
|
|
</head>
|
|
<body id="jdbctutr"><a name="jdbctutr"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">JDBC tutorial</h1>
|
|
<div><p>The following is a tutorial on writing a Java™ Database
|
|
Connectivity (JDBC) program and having it run on the an iSeries™ server
|
|
with the native JDBC driver. It is designed to show you the basic steps required
|
|
for your program to run JDBC.</p>
|
|
<div class="section"><p><a href="basicjdbc.htm#basicjdbc">Example: JDBC</a> creates a table
|
|
and populates it with some data. The program processes a query to get that
|
|
data out of the database and to display it on the screen.</p>
|
|
<p><strong>Run the
|
|
example program</strong></p>
|
|
<p>To run the example program, perform the following
|
|
steps:</p>
|
|
</div>
|
|
<ol><li class="stepexpand"><span>Copy the program to your workstation. </span><ol type="a"><li><span>Copy <a href="basicjdbc.htm#basicjdbc">Example: JDBC</a> and paste
|
|
it into a file on your workstation.</span></li>
|
|
<li><span>Save the file with the same name as the public class provided
|
|
and with the .java extension. In this case, you must name the file BasicJDBC.java
|
|
on your local workstation.</span></li>
|
|
</ol>
|
|
</li>
|
|
<li class="stepexpand"><span>Transfer the file from your workstation to your iSeries server.
|
|
From a command prompt, enter the following commands:</span> <pre> ftp <iSeries server name>
|
|
<Enter your user ID>
|
|
<Enter your password>
|
|
cd /home/cujo
|
|
put BasicJDBC.java
|
|
quit</pre>
|
|
<p>For these commands to work, you must have a directory
|
|
in which to put the file. In the example, /home/cujo is the location, but
|
|
you can use any location you want.</p>
|
|
<div class="note"><span class="notetitle">Note:</span> It is possible that the FTP
|
|
commands mentioned previously may be different for you based on how your server
|
|
is set up, but they should be similar. It does not matter how you transfer
|
|
the file to your iSeries server
|
|
as long as you transfer it into the integrated file system. Tools such as VisualAge<sup>®</sup> for Java can
|
|
fully automate this process for you.</div>
|
|
</li>
|
|
<li class="stepexpand"><span>Make sure you set your classpath to the directory where you put
|
|
the file in so that your Java commands find the file when you run
|
|
them. From a CL command line, you can use WRKENVVAR to see what environment
|
|
variables are set for your user profile.</span> <ul><li>If you see an environment variable named CLASSPATH, you must ensure that
|
|
the location where you put the .java file in is in the string of directories
|
|
listed there or add it if the location has not been specified.</li>
|
|
<li>If there is no CLASSPATH environment variable, you must add one. This
|
|
can be accomplished with the following command: <pre> ADDENVVAR ENVVAR(CLASSPATH)
|
|
VALUE('/home/cujo:/QIBM/ProdData/Java400/jdk13/lib/tools.jar')</pre>
|
|
</li>
|
|
</ul>
|
|
<div class="note"><span class="notetitle">Note:</span> To compile Java code from the CL command, you must
|
|
include the tools.jar file. This JAR file includes the javac command.</div>
|
|
</li>
|
|
<li class="stepexpand"><span>Compile the Java file into a class file. Enter the following
|
|
command from the CL command line:</span> <pre> java class(com.sun.tools.javac.Main) prop(BasicJDBC)
|
|
java BasicJDBC</pre>
|
|
<p>You can also compile the Java file
|
|
from QSH:</p>
|
|
<pre> cd /home/cujo
|
|
javac BasicJDBC.java</pre>
|
|
<p>QSH automatically ensures that the
|
|
tools.jar file can be found. As a result, you do not have to add it to your
|
|
classpath. The current directory is also in the classpath. By issuing the
|
|
change directory (cd) command, the BasicJDBC.java file is also found.</p>
|
|
<div class="note"><span class="notetitle">Note:</span> You
|
|
can also compile the file on your workstation and use FTP to send the class
|
|
file to your iSeries server
|
|
in binary mode. This is an example of Java's ability to run on any platform.</div>
|
|
<p>Run
|
|
the program by using the following command from either the CL command line
|
|
or from QSH: </p>
|
|
<pre> java BasicJDBC</pre>
|
|
<p>The output
|
|
is as follows:</p>
|
|
<pre> ----------------------
|
|
| 1 | Frank Johnson |
|
|
| |
|
|
| 2 | Neil Schwartz |
|
|
| |
|
|
| 3 | Ben Rodman |
|
|
| |
|
|
| 4 | Dan Gloore |
|
|
----------------------
|
|
There were 4 rows returned.
|
|
Output is complete.
|
|
Java program completed.</pre>
|
|
</li>
|
|
</ol>
|
|
<div class="section"><p>For more information on Java and JDBC, consult the following resources:</p>
|
|
<ul><li><a href="http://www-1.ibm.com/servers/eserver/iseries/toolbox/" target="_blank">IBM<sup>®</sup> Toolbox for Java JDBC driver external web site</a></li>
|
|
<li><a href="http://java.sun.com/products/jdbc/" target="_blank">Sun's
|
|
JDBC page</a></li>
|
|
<li><a href="mailto:JAVA400-L-SUB@midrange.com">Java/JDBC
|
|
forum for iSeries and iSeries users</a></li>
|
|
<li><a href="mailto:rchjdbc@us.ibm.com">IBM JDBC e-mail
|
|
address</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<ul class="ullinks">
|
|
<li class="ulchildlink"><strong><a href="basicjdbc.htm">Example: JDBC</a></strong><br />
|
|
This is an example of how to use the BasicJDBC program.</li>
|
|
</ul>
|
|
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="jdbcgets.htm" title="The Java Database Connectivity (JDBC) driver shipped with the Developer Kit for Java is called the Developer Kit for Java JDBC driver. This driver is also commonly known as the native JDBC driver.">Get started with JDBC</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="jdbctydr.htm" title="This topic defines the Java Database Connectivity (JDBC) driver types. Driver types are used to categorize the technology used to connect to the database. A JDBC driver vendor uses these types to describe how their product operates. Some JDBC driver types are better suited for some applications than others.">Types of JDBC drivers</a></div>
|
|
<div><a href="jdbcreqs.htm" title="Before you write and deploy your JDBC applications, you may need to include specific jar files in your classpath.">JDBC requirements</a></div>
|
|
</div>
|
|
<div class="reltasks"><strong>Related tasks</strong><br />
|
|
<div><a href="dasrjndi.htm" title="DataSources work hand-in-hand with the Java Naming and Directory Interface (JNDI). JNDI is a Java abstraction layer for directory services just as Java Database Connectivity (JDBC) is an abstraction layer for databases.">Use JNDI for the examples</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |