ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/vjdbc.htm

96 lines
5.8 KiB
HTML
Raw 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="JDBC classes" />
<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="vjdbc" />
<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 classes</title>
</head>
<body id="vjdbc"><a name="vjdbc"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">JDBC classes</h1>
<div><p></p>
<div class="section"><p>The JDBC graphical user interface components allow a Java™ program
to present various views and controls for accessing a database using SQL (Structured
Query Language) statements and queries.</p>
<p>The following components are
available:</p>
<ul><li><a href="vjdbcbm.htm#vjdbcbm">SQLStatementButton and SQLStatementMenuItem</a> are
either a button or a menu item that issues an SQL statement when clicked
or selected.</li>
<li><a href="vjdbcdoc.htm#vjdbcdoc">SQLStatementDocument</a> is a document
that can be used with any Java Foundation Classes (JFC) graphical
text component to issue an SQL statement.</li>
<li><a href="vjdbcfrm.htm#vjdbcfrm">SQLResultSetFormPane</a> presents
the results of an SQL query in a form.</li>
<li><a href="vjdbctbl.htm#vjdbctbl">SQLResultSetTablePane</a> presents
the results of an SQL query in a table.</li>
<li><a href="vjdbcmod.htm#vjdbcmod">SQLResultSetTableModel</a> manages
the results of an SQL query in a table.</li>
<li><a href="vjdbcbld.htm#vjdbcbld">SQLQueryBuilderPane</a> presents
an interactive tool for dynamically building SQL queries.</li>
</ul>
<p>All JDBC graphical user interface components communicate with the
database using a JDBC driver. The JDBC driver must be registered with the
JDBC driver manager in order for any of these components to work. The following
example registers the IBM<sup>®</sup> Toolbox for Java JDBC driver:</p>
<div class="p"><pre> // Register the JDBC driver.
DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());</pre>
</div>
</div>
<div class="section" id="vjdbc__sqlcon"><a name="vjdbc__sqlcon"><!-- --></a><h4 class="sectiontitle">SQL connections</h4><p>An <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#NAVBAR_TOP"> SQLConnection</a> object represents a connection to a database
using JDBC. <strong>The SQLConnection object is used with all of the JDBC graphical
user interface components.</strong></p>
<p>To use an SQLConnection, set the URL
property using the constructor or <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#SETURL(JAVA.LANG.STRING)"> setURL()</a>. This identifies the database to which the
connection is made. Other optional properties can be set:</p>
<ul><li>Use <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#SETPROPERTIES(JAVA.UTIL.PROPERTIES)"> setProperties()</a> to specify a set of JDBC connection
properties.</li>
<li>Use <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#SETUSERNAME(JAVA.LANG.STRING)"> setUserName()</a> to specify the user name for the connection.</li>
<li>Use <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#SETPASSWORD(JAVA.LANG.STRING)"> setPassword()</a> to specify the password for the connection.</li>
</ul>
<p>The actual connection to the database is not made when the SQLConnection
object is created. Instead, it is made when <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#GETCONNECTION()"> getConnection()</a> is called. This method is normally called
automatically by the JDBC graphical user interface components, but it can
be called at any time in order to control when the connection is made.</p>
<p>The
following example creates and initializes an SQLConnection object:</p>
<div class="p"><pre> // Create an SQLConnection object.
SQLConnection connection = new SQLConnection ();
// Set the URL and user name properties of the connection.
connection.setURL ("jdbc:as400://MySystem");
connection.setUserName ("Lisa");</pre>
</div>
<p>An SQLConnection object
can be used for more than one JDBC graphical user interface component. All
such components will use the same connection, which can improve performance
and resource usage. Alternately, each JDBC graphical user interface component
can use a different SQL object. It is sometimes necessary to use separate
connections, so that SQL statements are issued in different transactions.</p>
<p>When
the connection is no longer needed, close the SQLConnection object using <a href="javadoc/com/ibm/as400/vaccess/SQLConnection.html#CLOSE()"> close()</a>. This frees up JDBC resources on both the client
and server.</p>
</div>
</div>
</body>
</html>