JDBC classes

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.

The following components are available:

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® Toolbox for Java JDBC driver:

                       // Register the JDBC driver.
 DriverManager.registerDriver (new com.ibm.as400.access.AS400JDBCDriver ());

SQL connections

An SQLConnection object represents a connection to a database using JDBC. The SQLConnection object is used with all of the JDBC graphical user interface components.

To use an SQLConnection, set the URL property using the constructor or setURL(). This identifies the database to which the connection is made. Other optional properties can be set:

The actual connection to the database is not made when the SQLConnection object is created. Instead, it is made when getConnection() 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.

The following example creates and initializes an SQLConnection object:

                       // 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");

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.

When the connection is no longer needed, close the SQLConnection object using close(). This frees up JDBC resources on both the client and server.