alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (JdbcRowSet.java)

This example Java source code file (JdbcRowSet.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

jdbc, jdbcrowset, joinable, math, naming, rowsetwarning, sql, sqlexception

The JdbcRowSet.java Java example source code

/*
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package javax.sql.rowset;

import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.math.*;
import java.io.*;

/**
 * The standard interface that all standard implementations of
 * <code>JdbcRowSet must implement.
 *
 * <h3>1.0 Overview
 * A wrapper around a <code>ResultSet object that makes it possible
 * to use the result set as a JavaBeans™
 * component.  Thus, a <code>JdbcRowSet object can be one of the Beans that
 * a tool makes available for composing an application.  Because
 * a <code>JdbcRowSet is a connected rowset, that is, it continually
 * maintains its connection to a database using a JDBC technology-enabled
 * driver, it also effectively makes the driver a JavaBeans component.
 * <P>
 * Because it is always connected to its database, an instance of
 * <code>JdbcRowSet
 * can simply take calls invoked on it and in turn call them on its
 * <code>ResultSet object. As a consequence, a result set can, for
 * example, be a component in a Swing application.
 * <P>
 * Another advantage of a <code>JdbcRowSet object is that it can be
 * used to make a <code>ResultSet object scrollable and updatable.  All
 * <code>RowSet objects are by default scrollable and updatable. If
 * the driver and database being used do not support scrolling and/or updating
 * of result sets, an application can populate a <code>JdbcRowSet object
 * with the data of a <code>ResultSet object and then operate on the
 * <code>JdbcRowSet object as if it were the ResultSet
 * object.
 *
 * <h3>2.0 Creating a JdbcRowSet Object
 * The reference implementation of the <code>JdbcRowSet interface,
 * <code>JdbcRowSetImpl, provides an implementation of
 * the default constructor.  A new instance is initialized with
 * default values, which can be set with new values as needed. A
 * new instance is not really functional until its <code>execute
 * method is called. In general, this method does the following:
 * <UL>
 *   <LI> establishes a connection with a database
 *   <LI> creates a PreparedStatement object and sets any of its
 *        placeholder parameters
 *   <LI> executes the statement to create a ResultSet object
 * </UL>
 * If the <code>execute method is successful, it will set the
 * appropriate private <code>JdbcRowSet fields with the following:
 * <UL>
 *  <LI> a Connection object -- the connection between the rowset
 *       and the database
 *  <LI> a PreparedStatement object -- the query that produces
 *       the result set
 *  <LI> a ResultSet object -- the result set that the rowset's
 *       command produced and that is being made, in effect, a JavaBeans
 *       component
 * </UL>
 * If these fields have not been set, meaning that the <code>execute
 * method has not executed successfully, no methods other than
 * <code>execute and close may be called on the
 * rowset.  All other public methods will throw an exception.
 * <P>
 * Before calling the <code>execute method, however, the command
 * and properties needed for establishing a connection must be set.
 * The following code fragment creates a <code>JdbcRowSetImpl object,
 * sets the command and connection properties, sets the placeholder parameter,
 * and then invokes the method <code>execute.
 * <PRE>
 *     JdbcRowSetImpl jrs = new JdbcRowSetImpl();
 *     jrs.setCommand("SELECT * FROM TITLES WHERE TYPE = ?");
 *     jrs.setURL("jdbc:myDriver:myAttribute");
 *     jrs.setUsername("cervantes");
 *     jrs.setPassword("sancho");
 *     jrs.setString(1, "BIOGRAPHY");
 *     jrs.execute();
 * </PRE>
 * The variable <code>jrs now represents an instance of
 * <code>JdbcRowSetImpl that is a thin wrapper around the
 * <code>ResultSet object containing all the rows in the
 * table <code>TITLES where the type of book is biography.
 * At this point, operations called on <code>jrs will
 * affect the rows in the result set, which is effectively a JavaBeans
 * component.
 * <P>
 * The implementation of the <code>RowSet method execute in the
 * <code>JdbcRowSet reference implementation differs from that in the
 * <code>CachedRowSet™
 * reference implementation to account for the different
 * requirements of connected and disconnected <code>RowSet objects.
 * <p>
 *
 * @author Jonathan Bruce
 */

public interface JdbcRowSet extends RowSet, Joinable {

    /**
     * Retrieves a <code>boolean indicating whether rows marked
     * for deletion appear in the set of current rows. If <code>true is
     * returned, deleted rows are visible with the current rows. If
     * <code>false is returned, rows are not visible with the set of
     * current rows. The default value is <code>false.
     * <P>
     * Standard rowset implementations may choose to restrict this behavior
     * for security considerations or for certain deployment
     * scenarios. The visibility of deleted rows is implementation-defined
     * and does not represent standard behavior.
     * <P>
     * Note: Allowing deleted rows to remain visible complicates the behavior
     * of some standard JDBC <code>RowSet implementations methods.
     * However, most rowset users can simply ignore this extra detail because
     * only very specialized applications will likely want to take advantage of
     * this feature.
     *
     * @return <code>true if deleted rows are visible;
     *         <code>false otherwise
     * @exception SQLException if a rowset implementation is unable to
     *          to determine whether rows marked for deletion remain visible
     * @see #setShowDeleted
     */
    public boolean getShowDeleted() throws SQLException;

    /**
     * Sets the property <code>showDeleted to the given
     * <code>boolean value. This property determines whether
     * rows marked for deletion continue to appear in the set of current rows.
     * If the value is set to <code>true, deleted rows are immediately
     * visible with the set of current rows. If the value is set to
     * <code>false, the deleted rows are set as invisible with the
     * current set of rows.
     * <P>
     * Standard rowset implementations may choose to restrict this behavior
     * for security considerations or for certain deployment
     * scenarios. This is left as implementation-defined and does not
     * represent standard behavior.
     *
     * @param b <code>true if deleted rows should be shown;
     *              <code>false otherwise
     * @exception SQLException if a rowset implementation is unable to
     *          to reset whether deleted rows should be visible
     * @see #getShowDeleted
     */
    public void setShowDeleted(boolean b) throws SQLException;

    /**
     * Retrieves the first warning reported by calls on this <code>JdbcRowSet
     * object.
     * If a second warning was reported on this <code>JdbcRowSet object,
     * it will be chained to the first warning and can be retrieved by
     * calling the method <code>RowSetWarning.getNextWarning on the
     * first warning. Subsequent warnings on this <code>JdbcRowSet
     * object will be chained to the <code>RowSetWarning objects
     * returned by the method <code>RowSetWarning.getNextWarning.
     *
     * The warning chain is automatically cleared each time a new row is read.
     * This method may not be called on a <code>RowSet object
     * that has been closed;
     * doing so will cause an <code>SQLException to be thrown.
     * <P>
     * Because it is always connected to its data source, a <code>JdbcRowSet
     * object can rely on the presence of active
     * <code>Statement, Connection, and ResultSet
     * instances. This means that  applications can obtain additional
     * <code>SQLWarning
     * notifications by calling the <code>getNextWarning methods that
     * they provide.
     * Disconnected <code>Rowset objects, such as a
     * <code>CachedRowSet object, do not have access to
     * these <code>getNextWarning methods.
     *
     * @return the first <code>RowSetWarning
     * object reported on this <code>JdbcRowSet object
     * or <code>null if there are none
     * @throws SQLException if this method is called on a closed
     * <code>JdbcRowSet object
     * @see RowSetWarning
     */
    public RowSetWarning getRowSetWarnings() throws SQLException;

   /**
    * Each <code>JdbcRowSet contains a Connection object from
    * the <code>ResultSet or JDBC properties passed to it's constructors.
    * This method wraps the <code>Connection commit method to allow flexible
    * auto commit or non auto commit transactional control support.
    * <p>
    * Makes all changes made since the previous commit/rollback permanent
    * and releases any database locks currently held by this Connection
    * object. This method should be used only when auto-commit mode has
    * been disabled.
    *
    * @throws SQLException if a database access error occurs or this
    * Connection object within this <code>JdbcRowSet is in auto-commit mode
    * @see java.sql.Connection#setAutoCommit
    */
    public void commit() throws SQLException;


   /**
    * Each <code>JdbcRowSet contains a Connection object from
    * the original <code>ResultSet or JDBC properties passed to it. This
    * method wraps the <code>Connection's getAutoCommit method
    * to allow an application to determine the <code>JdbcRowSet transaction
    * behavior.
    * <p>
    * Sets this connection's auto-commit mode to the given state. If a
    * connection is in auto-commit mode, then all its SQL statements will
    * be executed and committed as individual transactions. Otherwise, its
    * SQL statements are grouped into transactions that are terminated by a
    * call to either the method commit or the method rollback. By default,
    * new connections are in auto-commit mode.
    *
    * @return {@code true} if auto-commit is enabled; {@code false} otherwise
    * @throws SQLException if a database access error occurs
    * @see java.sql.Connection#getAutoCommit()
    */
    public boolean getAutoCommit() throws SQLException;


   /**
    * Each <code>JdbcRowSet contains a Connection object from
    * the original <code>ResultSet or JDBC properties passed to it. This
    * method wraps the <code>Connection's getAutoCommit method
    * to allow an application to set the <code>JdbcRowSet transaction behavior.
    * <p>
    * Sets the current auto-commit mode for this <code>Connection object.
    * @param autoCommit {@code true} to enable auto-commit; {@code false} to
    * disable auto-commit
    * @throws SQLException if a database access error occurs
    * @see java.sql.Connection#setAutoCommit(boolean)
    */
    public void setAutoCommit(boolean autoCommit) throws SQLException;

    /**
     * Each <code>JdbcRowSet contains a Connection object from
     * the original <code>ResultSet or JDBC properties passed to it.
     * Undoes all changes made in the current transaction and releases any
     * database locks currently held by this <code>Connection object. This method
     * should be used only when auto-commit mode has been disabled.
     *
     * @throws SQLException if a database access error occurs or this <code>Connection
     * object within this <code>JdbcRowSet is in auto-commit mode.
     * @see #rollback(Savepoint)
     */
     public void rollback() throws SQLException;


    /**
     * Each <code>JdbcRowSet contains a Connection object from
     * the original <code>ResultSet or JDBC properties passed to it.
     * Undoes all changes made in the current transaction to the last set savepoint
     * and releases any database locks currently held by this <code>Connection
     * object. This method should be used only when auto-commit mode has been disabled.
     * @param s The {@code Savepoint} to rollback to
     * @throws SQLException if a database access error occurs or this <code>Connection
     * object within this <code>JdbcRowSet is in auto-commit mode.
     * @see #rollback
     */
    public void rollback(Savepoint s) throws SQLException;

}

Other Java examples (source code examples)

Here is a short list of links related to this Java JdbcRowSet.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.