org.example.project.database
Class GenericTable

java.lang.Object
  extended by org.example.project.database.GenericTable

public abstract class GenericTable
extends java.lang.Object

Abstract class that defines a set of commonly used database access methods. This class cannot be instantiated, but is rather designed to be extended by table-specific wrapper classes.

Version:
0.1
Author:
Jason Kelly

Field Summary
 java.sql.ResultSet keyResultSet
          Stores the results from running a SQL query.
 java.sql.ResultSet resultSet
          Stores the results from running a SQL query.
 
Constructor Summary
GenericTable(java.sql.Connection con)
          Initialise the database connection for this class.
 
Method Summary
 void afterLast()
          Moves the cursor to the end of the current ResultSet object, just after the last row.
 void beforeFirst()
          Moves the cursor to the front of the current ResultSet object, just before the first row.
 void clearPreparedParameters(java.lang.String id)
          Clears the parameters that have been associated with the prepared statement that is identified by the given ID.
 void close()
          Closes the Statement and ResultSet objects and releases the database and JDBC resources asociated with these objects.
 void commit()
          Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection object.
 void createPreparedStatement(java.lang.String id, java.lang.String query)
          Creates and stores a prepared statement for later use.
 void createPreparedStatement(java.lang.String id, java.lang.String query, int autoGeneratedKeys)
          Creates and stores the default prepared statement as does createPreparedStatement(String, String), except that the user may specify whether or not this statement can return auto-generated keys.
 void createPreparedStatement(java.lang.String id, java.lang.String query, int resultSetType, int resultSetConcurrency)
          Creates and stores a prepared statement for later use.
 void createPreparedStatement(java.lang.String id, java.lang.String query, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Creates and stores a prepared statement for later use.
 void deletePreparedStatement(java.lang.String id)
          Deletes any prepared statement that is represented by the given ID.
 void deleteRow()
          Deletes the current row from the ResultSet object and from the underlying database.
 void executePreparedQuery(java.lang.String id)
          Executes the prepared statement associated with the given ID.
 int executePreparedUpdate(java.lang.String id)
          Executes the prepared statement associated with the given ID.
 void executeQuery(java.lang.String query)
           Executes the given SQL query, and populates the result set with the query results.
 void executeQuery(java.lang.String query, int resultSetType, int resultSetConcurrency)
          Executes the given SQL query and populates the result set.
 void executeQuery(java.lang.String query, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Executes the given SQL query and populates the result set.
 int executeUpdate(java.lang.String query)
          Executes the given SQL query, which may be an INSERT, UPDATE, or DELETE query, or a query which returns nothing.
 int executeUpdate(java.lang.String query, int autoGeneratedKeys)
          Executes the given SQL query and signals the driver with the given flag about whether the auto-generated keys produced by this query should be made available for retrieval.
 boolean first()
          Moves the cursor to the first row in the current ResultSet object.
 boolean getAutoCommit()
          Retrieves the current auto-commit status for the Connection object.
 void getGeneratedKeys()
          Populates the key result set with any auto-generated keys created as a result of executing the query from either executeUpdate(String) or executeUpdate(String, int).
 void getPreparedGeneratedKeys(java.lang.String id)
          Populates the key result set with any auto-generated keys created as a result of executing the prepared query using executePreparedUpdate(String).
 int getTransactionIsolation()
          Retrieves the Connection object's current transaction isolation level.
 void insertRow()
          Inserts the contents of the insert row into the ResultSet object and into the database.
 boolean isAfterLast()
          Retrieves whether the cursor is after the last row in the current ResultSet object.
 boolean isBeforeFirst()
          Retrieves whether the cursor is before the first row in the current ResultSet object.
 boolean isFirst()
          Retrieves whether the cursor is on the first row of the current ResultSet object.
 boolean isLast()
          Retrieves whether the cursor is on the last row of the current ResultSet object.
 boolean last()
          Moves the cursor to the last row in the current ResultSet object.
 void moveToCurrentRow()
          Moves the cursor to the remembered cursor position, usually the current row.
 void moveToInsertRow()
          Moves the cursor to the insert row.
 boolean next()
          Moves the current ResultSet cursor down one row from its current position.
 boolean previous()
          Moves the cursor to the previous row in the current ResultSet object.
 void refreshRow()
          Refreshes the current row with its most recent value in the database.
 void rollback()
          Undoes all changes made in the current transaction and releases any database locks currently held by the Connection object.
 void setArray(java.lang.String id, int parameterIndex, java.sql.Array x)
          Sets the designated parameter of the specified PreparedStatement to the given Array object.
 void setAsciiStream(java.lang.String id, int parameterIndex, java.io.InputStream x, int length)
          Sets the designated parameter of the specified PreparedStatement to the given input stream, which will have the specified number of bytes.
 void setAutoCommit(boolean autoCommit)
          Sets this connection's auto-commit mode to the given state.
 void setBigDecimal(java.lang.String id, int parameterIndex, java.math.BigDecimal x)
          Sets the designated parameter of the specified PreparedStatement to the given java.math.BigDecimal value.
 void setBinaryStream(java.lang.String id, int parameterIndex, java.io.InputStream x, int length)
          Sets the designated parameter of the specified PreparedStatement to the given input stream, which will have the specified number of bytes.
 void setBlob(java.lang.String id, int parameterIndex, java.sql.Blob x)
          Sets the designated parameter of the specified PreparedStatement to the given Blob object.
 void setBoolean(java.lang.String id, int parameterIndex, boolean x)
          Sets the designated parameter of the specified PreparedStatement to the given Java boolean value.
 void setByte(java.lang.String id, int parameterIndex, byte x)
          Sets the designated parameter of the specified PreparedStatement to the given Java byte value.
 void setBytes(java.lang.String id, int parameterIndex, byte[] x)
          Sets the designated parameter of the specified PreparedStatement to the given Java array of bytes.
 void setCharacterStream(java.lang.String id, int parameterIndex, java.io.Reader x, int length)
          Sets the designated parameter of the specified PreparedStatement to the given Reader object, which is the given number of characters long.
 void setClob(java.lang.String id, int parameterIndex, java.sql.Clob x)
          Sets the designated parameter of the specified PreparedStatement to the given Clob object.
 void setDate(java.lang.String id, int parameterIndex, java.sql.Date x)
          Sets the designated parameter of the specified PreparedStatement to the given java.sql.Date value.
 void setDate(java.lang.String id, int parameterIndex, java.sql.Date x, java.util.Calendar cal)
          Sets the designated parameter of the specified PreparedStatement to the given java.sql.Date value, using the given Calendar object.
 void setDouble(java.lang.String id, int parameterIndex, double x)
          Sets the designated parameter of the specified PreparedStatement to the given Java double value.
 void setFloat(java.lang.String id, int parameterIndex, float x)
          Sets the designated parameter of the specified PreparedStatement to the given Java float value.
 void setInt(java.lang.String id, int parameterIndex, int x)
          Sets the designated parameter of the specified PreparedStatement to the given Java int value.
 void setLong(java.lang.String id, int parameterIndex, long x)
          Sets the designated parameter of the specified PreparedStatement to the given Java long value.
 void setNull(java.lang.String id, int parameterIndex, int sqlType)
           Sets the designated parameter of the specified PreparedStatement to SQL NULL.
 void setNull(java.lang.String id, int parameterIndex, int sqlType, java.lang.String typeName)
          Sets the designated parameter of the specified PreparedStatement to SQL NULL.
 void setObject(java.lang.String id, int parameterIndex, java.lang.Object x)
          Sets the value of the designated parameter for the given PreparedStatement using the given object.
 void setObject(java.lang.String id, int parameterIndex, java.lang.Object x, int targetSqlType)
          Sets the value of the designated parameter for the specified PreparedStatement with the given object.
 void setObject(java.lang.String id, int parameterIndex, java.lang.Object x, int targetSqlType, int scale)
          Sets the value of the designated parameter for the given PreparedStatement using the given object.
 void setRef(java.lang.String id, int parameterIndex, java.sql.Ref x)
          Sets the designated parameter for the specified PreparedStatement to the given REF(<structured-type>) value.
 void setShort(java.lang.String id, int parameterIndex, short x)
          Sets the designated parameter for the specified PreparedStatement to the given Java short value.
 void setString(java.lang.String id, int parameterIndex, java.lang.String x)
          Sets the designated parameter for the specified PreparedStatement to the given Java String value.
 void setTime(java.lang.String id, int parameterIndex, java.sql.Time x)
          Sets the designated parameter for the specified PreparedStatement to the given java.sql.Time value.
 void setTime(java.lang.String id, int parameterIndex, java.sql.Time x, java.util.Calendar cal)
          Sets the designated parameter for the specified PreparedStatement to the given java.sql.Time value, using the given Calendar object.
 void setTimestamp(java.lang.String id, int parameterIndex, java.sql.Timestamp x)
          Sets the designated parameter for the specified PreparedStatement to the given java.sql.Timestamp value.
 void setTimestamp(java.lang.String id, int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal)
          Sets the designated parameter for the specified PreparedStatement to the given java.sql.Timestamp value, using the given Calendar object.
 void setTransactionIsolation(int isolationLevel)
          Attempts to change the transaction isolation level for the database connection object to the one given.
 void setURL(java.lang.String id, int parameterIndex, java.net.URL x)
          Sets the designated parameter for the specified PreparedStatement to the given java.net.URL value.
 void updateRow()
          Updates the underlying database with the new contents of the current row of the ResultSet object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resultSet

public java.sql.ResultSet resultSet
Stores the results from running a SQL query.


keyResultSet

public java.sql.ResultSet keyResultSet
Stores the results from running a SQL query.

Constructor Detail

GenericTable

public GenericTable(java.sql.Connection con)
Initialise the database connection for this class. Concrete implementations of this class must call this constructor (using super( connection )) with the database connection object.

Parameters:
con - database connection.
Method Detail

executeQuery

public void executeQuery(java.lang.String query)
                  throws java.sql.SQLException

Executes the given SQL query, and populates the result set with the query results. This method uses a Statement object to execute the query, and the result set returned is read only and the result set cursor can only move forward.

To use a prepared statement instead, see executePreparedQuery(String).

Parameters:
query - SQL query to execute.
Throws:
java.sql.SQLException - if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object.

executeQuery

public void executeQuery(java.lang.String query,
                         int resultSetType,
                         int resultSetConcurrency)
                  throws java.sql.SQLException
Executes the given SQL query and populates the result set. The result set will have the given type and concurrency.

Parameters:
query - the SQL query that returns a result set.
resultSetType - one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Throws:
java.sql.SQLException - if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object.

executeQuery

public void executeQuery(java.lang.String query,
                         int resultSetType,
                         int resultSetConcurrency,
                         int resultSetHoldability)
                  throws java.sql.SQLException
Executes the given SQL query and populates the result set. The result set will have the given type, concurrency, and holdability.

Parameters:
query - the SQL query that returns a result set.
resultSetType - one of the following ResultSet constants: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - one of the following ResultSet constants: ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetHoldability - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Throws:
java.sql.SQLException - if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object.

executeUpdate

public int executeUpdate(java.lang.String query)
                  throws java.sql.SQLException
Executes the given SQL query, which may be an INSERT, UPDATE, or DELETE query, or a query which returns nothing.

Parameters:
query - the query to execute.
Returns:
for an INSERT, UPDATE, or DELETE query the number of rows affected; for a query that return nothing, 0.
Throws:
java.sql.SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object.

executeUpdate

public int executeUpdate(java.lang.String query,
                         int autoGeneratedKeys)
                  throws java.sql.SQLException
Executes the given SQL query and signals the driver with the given flag about whether the auto-generated keys produced by this query should be made available for retrieval.

Parameters:
query - the query to execute; must be an INSERT, UPDATE, DELETE, or DDL query.
autoGeneratedKeys - a flag indicating whether auto-generated keys should be made available for retrieval; one of the following constants: Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS.
Returns:
either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
Throws:
java.sql.SQLException - if a database access error occurs, the given SQL statement returns a ResultSet object, or the given constant is not one of those allowed.

getGeneratedKeys

public void getGeneratedKeys()
                      throws java.sql.SQLException
Populates the key result set with any auto-generated keys created as a result of executing the query from either executeUpdate(String) or executeUpdate(String, int). If this query did not generate any keys, the keys result set will be populated by an empty ResultSet object.

Throws:
java.sql.SQLException - if a database access error occurs.

createPreparedStatement

public void createPreparedStatement(java.lang.String id,
                                    java.lang.String query)
                             throws java.sql.SQLException,
                                    DuplicateIdentifierException
Creates and stores a prepared statement for later use. Prepared statements are usually parametric statements that get executed often. Each prepared statement uses a string ID to identify it, and all IDs must be unique. Any returned result set will be read only and forward-scrollable only.

Parameters:
id - used to identify this prepared statement.
query - parameterised query that may have one or more '?' parameters.
Throws:
java.sql.SQLException - if a database access error occurs.
DuplicateIdentifierException - if the given ID is a duplicate.

createPreparedStatement

public void createPreparedStatement(java.lang.String id,
                                    java.lang.String query,
                                    int autoGeneratedKeys)
                             throws java.sql.SQLException,
                                    DuplicateIdentifierException
Creates and stores the default prepared statement as does createPreparedStatement(String, String), except that the user may specify whether or not this statement can return auto-generated keys. Statements that do not auto-generate keys ignore this option.

Parameters:
id - used to identify this prepared statement.
query - parameterised query that may have one or more '?' parameters.
autoGeneratedKeys - a flag indicating whether auto-generated keys should be returned; one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS.
Throws:
java.sql.SQLException - if a database access error occurs or the given parameter is not a Statement constant indicating whether auto-generated keys should be returned.
DuplicateIdentifierException - if the given ID is a duplicate.

createPreparedStatement

public void createPreparedStatement(java.lang.String id,
                                    java.lang.String query,
                                    int resultSetType,
                                    int resultSetConcurrency)
                             throws java.sql.SQLException,
                                    DuplicateIdentifierException
Creates and stores a prepared statement for later use. Any returned result set will have the specified type and concurrency.

Parameters:
id - string ID representing this prepared statement.
query - statement to prepare for execution (may include parameters).
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Throws:
java.sql.SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency.
DuplicateIdentifierException - if the given ID is already mapped to a prepared statement.

createPreparedStatement

public void createPreparedStatement(java.lang.String id,
                                    java.lang.String query,
                                    int resultSetType,
                                    int resultSetConcurrency,
                                    int resultSetHoldability)
                             throws java.sql.SQLException,
                                    DuplicateIdentifierException
Creates and stores a prepared statement for later use. Any returned result set will have the specified type, concurrency, and holdability.

Parameters:
id - string ID representing this prepared statement.
query - statement to prepare for execution (may include parameters).
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetHoldability - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Throws:
java.sql.SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type, concurrency, and holdability.
DuplicateIdentifierException - if the given ID is already mapped to a prepared statement.

deletePreparedStatement

public void deletePreparedStatement(java.lang.String id)
Deletes any prepared statement that is represented by the given ID. It is posible to call this method giving it an ID that has not been mapped yet. Calling this method with an ID garauntees that the ID is not mapped.

Parameters:
id - ID of prepared statement to delete.

executePreparedQuery

public void executePreparedQuery(java.lang.String id)
                          throws java.sql.SQLException,
                                 UndefinedStatementException
Executes the prepared statement associated with the given ID. The prepared statement is expected to return information in a result set.

Parameters:
id - prepared statement ID.
Throws:
java.sql.SQLException - if a database access error occurs or the SQL statement does not return a ResultSet object.
UndefinedStatementException - if the given ID is not associated with a prepared statement.

executePreparedUpdate

public int executePreparedUpdate(java.lang.String id)
                          throws java.sql.SQLException,
                                 UndefinedStatementException
Executes the prepared statement associated with the given ID. The prepared statement is expected to return and integer, which would be either the number of rows affected by an INSERT, UPDATE, or DELETE query, or 0 (zero) for queries that do not return any row affected number, such as DDL queries.

Parameters:
id - prepared statement ID.
Returns:
number of rows affected.
Throws:
java.sql.SQLException - if a database access error occurs or the SQL statement returns a ResultSet object.
UndefinedStatementException - if the given ID is not associated with a prepared statement.

getPreparedGeneratedKeys

public void getPreparedGeneratedKeys(java.lang.String id)
                              throws java.sql.SQLException,
                                     UndefinedStatementException
Populates the key result set with any auto-generated keys created as a result of executing the prepared query using executePreparedUpdate(String). If this query did not generate any keys, the keys result set will be populated by an empty ResultSet object.

Parameters:
id - prepared statement ID.
Throws:
java.sql.SQLException - if a database access error occurs.
UndefinedStatementException - if the given ID is not associated with a prepared statement.

clearPreparedParameters

public void clearPreparedParameters(java.lang.String id)
                             throws java.sql.SQLException,
                                    UndefinedStatementException
Clears the parameters that have been associated with the prepared statement that is identified by the given ID.

Parameters:
id - identifies the prepared statement to clear the parameters of.
Throws:
java.sql.SQLException - if an error occurs during the clear process.
UndefinedStatementException - if the given ID is not mapped to a statement.

setArray

public void setArray(java.lang.String id,
                     int parameterIndex,
                     java.sql.Array x)
              throws java.sql.SQLException,
                     UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Array object. The driver converts this to an SQL ARRAY value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - an Array object that maps an SQL ARRAY value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setAsciiStream

public void setAsciiStream(java.lang.String id,
                           int parameterIndex,
                           java.io.InputStream x,
                           int length)
                    throws java.sql.SQLException,
                           UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given input stream, which will have the specified number of bytes.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the Java input stream that contains the ASCII parameter value
length - the number of bytes in the stream
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setAsciiStream(int,InputStream,int)

setBigDecimal

public void setBigDecimal(java.lang.String id,
                          int parameterIndex,
                          java.math.BigDecimal x)
                   throws java.sql.SQLException,
                          UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given java.math.BigDecimal value. The driver converts this to an SQL NUMERIC value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setBinaryStream

public void setBinaryStream(java.lang.String id,
                            int parameterIndex,
                            java.io.InputStream x,
                            int length)
                     throws java.sql.SQLException,
                            UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given input stream, which will have the specified number of bytes.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the java input stream which contains the binary parameter value
length - the number of bytes in the stream
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setBinaryStream(int,InputStream,int)

setBlob

public void setBlob(java.lang.String id,
                    int parameterIndex,
                    java.sql.Blob x)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Blob object. The driver converts this to an SQL BLOB value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - a Blob object that maps an SQL BLOB value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setBoolean

public void setBoolean(java.lang.String id,
                       int parameterIndex,
                       boolean x)
                throws java.sql.SQLException,
                       UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java boolean value. The driver converts this to an SQL BIT value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setByte

public void setByte(java.lang.String id,
                    int parameterIndex,
                    byte x)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java byte value. The driver converts this to an SQL TINYINT value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setBytes

public void setBytes(java.lang.String id,
                     int parameterIndex,
                     byte[] x)
              throws java.sql.SQLException,
                     UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java array of bytes. The driver converts this to an SQL VARBINARY or LONGVARBINARY (depending on the argument's size relative to the driver's limits on VARBINARY values) when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setCharacterStream

public void setCharacterStream(java.lang.String id,
                               int parameterIndex,
                               java.io.Reader x,
                               int length)
                        throws java.sql.SQLException,
                               UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Reader object, which is the given number of characters long.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - java.io.Reader object that contains the Unicode data
length - the number of characters in the stream
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setBinaryStream(int,InputStream,int)

setClob

public void setClob(java.lang.String id,
                    int parameterIndex,
                    java.sql.Clob x)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Clob object. The driver converts this to an SQL CLOB value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - a Clob object that maps an SQL CLOB value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setDate

public void setDate(java.lang.String id,
                    int parameterIndex,
                    java.sql.Date x)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given java.sql.Date value. The driver converts this to an SQL DATE value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setDate

public void setDate(java.lang.String id,
                    int parameterIndex,
                    java.sql.Date x,
                    java.util.Calendar cal)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given java.sql.Date value, using the given Calendar object. The driver uses the Calendar object to construct an SQL DATE value, which the driver then sends to the database. With a Calendar object, the driver can calculate the date taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
cal - the Calendar object the driver will use to construct the date
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setDouble

public void setDouble(java.lang.String id,
                      int parameterIndex,
                      double x)
               throws java.sql.SQLException,
                      UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java double value. The driver converts this to an SQL DOUBLE value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setFloat

public void setFloat(java.lang.String id,
                     int parameterIndex,
                     float x)
              throws java.sql.SQLException,
                     UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java float value. The driver converts this to an SQL FLOAT value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setInt

public void setInt(java.lang.String id,
                   int parameterIndex,
                   int x)
            throws java.sql.SQLException,
                   UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java int value. The driver converts this to an SQL INTEGER value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setLong

public void setLong(java.lang.String id,
                    int parameterIndex,
                    long x)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to the given Java long value. The driver converts this to an SQL BIGINT value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setNull

public void setNull(java.lang.String id,
                    int parameterIndex,
                    int sqlType)
             throws java.sql.SQLException,
                    UndefinedStatementException

Sets the designated parameter of the specified PreparedStatement to SQL NULL.

Note: You must specify the parameter's SQL type.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
sqlType - the SQL type code defined in java.sql.Types
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setNull

public void setNull(java.lang.String id,
                    int parameterIndex,
                    int sqlType,
                    java.lang.String typeName)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter of the specified PreparedStatement to SQL NULL. This version of the method setNull should be used for user-defined types and REF type parameters. Examples of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and named array types.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
sqlType - the SQL type code defined in java.sql.Types
typeName - the fully-qualified name of an SQL user-defined type; ignored if the parameter is not a user-defined type or REF
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setNull(int,int,String)

setObject

public void setObject(java.lang.String id,
                      int parameterIndex,
                      java.lang.Object x)
               throws java.sql.SQLException,
                      UndefinedStatementException
Sets the value of the designated parameter for the given PreparedStatement using the given object. The second parameter must be of type Object; therefore, the java.lang equivalent objects should be used for built-in types.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setObject(int,Object)

setObject

public void setObject(java.lang.String id,
                      int parameterIndex,
                      java.lang.Object x,
                      int targetSqlType)
               throws java.sql.SQLException,
                      UndefinedStatementException
Sets the value of the designated parameter for the specified PreparedStatement with the given object. This method is like the method setObject below, except that it assumes a scale of zero.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
targetSqlType - the SQL type code defined in java.sql.Types
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setObject(int,Object,int)

setObject

public void setObject(java.lang.String id,
                      int parameterIndex,
                      java.lang.Object x,
                      int targetSqlType,
                      int scale)
               throws java.sql.SQLException,
                      UndefinedStatementException
Sets the value of the designated parameter for the given PreparedStatement using the given object. The second parameter must be of type Object; therefore, the java.lang equivalent objects should be used for built-in types.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
targetSqlType - the SQL type code defined in java.sql.Types
scale - for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types, this is the number of digits after the decimal point. For all other types, this value will be ignored
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement
See Also:
java.sql.PreparedStatement.setObject(int,Object,int,int)

setRef

public void setRef(java.lang.String id,
                   int parameterIndex,
                   java.sql.Ref x)
            throws java.sql.SQLException,
                   UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given REF(<structured-type>) value. The driver converts this to an SQL REF value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setShort

public void setShort(java.lang.String id,
                     int parameterIndex,
                     short x)
              throws java.sql.SQLException,
                     UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given Java short value. The driver converts this to an SQL SMALLINT value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setString

public void setString(java.lang.String id,
                      int parameterIndex,
                      java.lang.String x)
               throws java.sql.SQLException,
                      UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given Java String value. The driver converts this to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's size relative to the driver's limits on VARCHAR values) when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setTime

public void setTime(java.lang.String id,
                    int parameterIndex,
                    java.sql.Time x)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given java.sql.Time value. The driver converts this to an SQL TIME value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setTime

public void setTime(java.lang.String id,
                    int parameterIndex,
                    java.sql.Time x,
                    java.util.Calendar cal)
             throws java.sql.SQLException,
                    UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given java.sql.Time value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIME value, which the driver then sends to the database. With a Calendar object, the driver can calculate the time taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
cal - the Calendar object the driver will use to construct the time
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setTimestamp

public void setTimestamp(java.lang.String id,
                         int parameterIndex,
                         java.sql.Timestamp x)
                  throws java.sql.SQLException,
                         UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given java.sql.Timestamp value. The driver converts this to an SQL TIMESTAMP value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setTimestamp

public void setTimestamp(java.lang.String id,
                         int parameterIndex,
                         java.sql.Timestamp x,
                         java.util.Calendar cal)
                  throws java.sql.SQLException,
                         UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given java.sql.Timestamp value, using the given Calendar object. The driver uses the Calendar object to construct an SQL TIMESTAMP value, which the driver then sends to the database. With a Calendar object, the driver can calculate the timestamp taking into account a custom timezone. If no Calendar object is specified, the driver uses the default timezone, which is that of the virtual machine running the application.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
cal - the Calendar object the driver will use to construct the time
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setURL

public void setURL(java.lang.String id,
                   int parameterIndex,
                   java.net.URL x)
            throws java.sql.SQLException,
                   UndefinedStatementException
Sets the designated parameter for the specified PreparedStatement to the given java.net.URL value. The driver converts this to an SQL DATALINK value when it sends it to the database.

Parameters:
id - PreparedStatement id
parameterIndex - the first parameter is 1, the second is 2, ...
x - the parameter value
Throws:
java.sql.SQLException - if a database access error occurs
UndefinedStatementException - if the given ID is not mapped to a statement

setTransactionIsolation

public void setTransactionIsolation(int isolationLevel)
                             throws java.sql.SQLException
Attempts to change the transaction isolation level for the database connection object to the one given.

Parameters:
isolationLevel - one of the following Connection constants: Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ, or Connection.TRANSACTION_SERIALIZABLE. (Note that Connection.TRANSACTION_NONE cannot be used because it specifies that transactions are not supported.)
Throws:
java.sql.SQLException - if a database access error occurs or the given parameter is not one of the Connection constants
See Also:
java.sql.Connection.setTransactionIsolation(int)

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Retrieves the Connection object's current transaction isolation level.

Returns:
the current transaction isolation level, which will be one of the following constants: Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ, Connection.TRANSACTION_SERIALIZABLE, or Connection.TRANSACTION_NONE
Throws:
java.sql.SQLException - if a database access error occurs

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Sets this connection's auto-commit mode to the given state. By default, new connections are in auto-commit mode.

Parameters:
autoCommit - true to enable auto-commit mode; false to disable it
Throws:
java.sql.SQLException - if a database access error occurs
See Also:
java.sql.Connection.setAutoCommit(boolean)

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Retrieves the current auto-commit status for the Connection object.

Returns:
the current state of the Connection object's auto-commit mode
Throws:
java.sql.SQLException - if a database access error occurs

commit

public void commit()
            throws java.sql.SQLException
Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by the Connection object. This method should be used only when auto-commit mode has been disabled.

Throws:
java.sql.SQLException - if a database access error occurs or the Connection object is in auto-commit mode

rollback

public void rollback()
              throws java.sql.SQLException
Undoes all changes made in the current transaction and releases any database locks currently held by the Connection object. This method should be used only when auto-commit mode has been disabled.

Throws:
java.sql.SQLException - if a database access error occurs or this Connection object is in auto-commit mode

next

public boolean next()
             throws java.sql.SQLException
Moves the current ResultSet cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row.

Returns:
true if the new current row is valid; false if there are no more rows
Throws:
java.sql.SQLException - if a database access error occurs

previous

public boolean previous()
                 throws java.sql.SQLException
Moves the cursor to the previous row in the current ResultSet object.

Returns:
true if the cursor is on a valid row; false if it is off the result set
Throws:
java.sql.SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY

first

public boolean first()
              throws java.sql.SQLException
Moves the cursor to the first row in the current ResultSet object.

Returns:
true if the cursor is on a valid row; false if there are no rows in the result set
Throws:
java.sql.SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY

isFirst

public boolean isFirst()
                throws java.sql.SQLException
Retrieves whether the cursor is on the first row of the current ResultSet object.

Returns:
true if the cursor is on the first row; false otherwise
Throws:
java.sql.SQLException - if a database access error occurs

last

public boolean last()
             throws java.sql.SQLException
Moves the cursor to the last row in the current ResultSet object.

Returns:
true if the cursor is on a valid row; false if there are no rows in the result set
Throws:
java.sql.SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY

isLast

public boolean isLast()
               throws java.sql.SQLException
Retrieves whether the cursor is on the last row of the current ResultSet object. Calling isLast may be expensive as the JDBC driver might have to try to fetch ahead one row in order to determine if the current row is in fact the last row.

Returns:
true if the cursor is on the last row; false otherwise
Throws:
java.sql.SQLException - if a database access error occurs

beforeFirst

public void beforeFirst()
                 throws java.sql.SQLException
Moves the cursor to the front of the current ResultSet object, just before the first row. This method has no effect if the result set contains no rows.

Throws:
java.sql.SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY

isBeforeFirst

public boolean isBeforeFirst()
                      throws java.sql.SQLException
Retrieves whether the cursor is before the first row in the current ResultSet object.

Returns:
true if the cursor is before the first row; false if the cursor is at any other position or the result set contains no rows
Throws:
java.sql.SQLException - if a database access error occurs

afterLast

public void afterLast()
               throws java.sql.SQLException
Moves the cursor to the end of the current ResultSet object, just after the last row. This method has no effect if the result set contains no rows.

Throws:
java.sql.SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY

isAfterLast

public boolean isAfterLast()
                    throws java.sql.SQLException
Retrieves whether the cursor is after the last row in the current ResultSet object.

Returns:
true if the cursor is after the last row; false if the cursor is at any other position or the result set contains no rows
Throws:
java.sql.SQLException - if a database access error occurs

updateRow

public void updateRow()
               throws java.sql.SQLException
Updates the underlying database with the new contents of the current row of the ResultSet object. This method cannot be called when the cursor is on the insert row.

Throws:
java.sql.SQLException - if a database access error occurs or if this method is called when the cursor is on the insert row

deleteRow

public void deleteRow()
               throws java.sql.SQLException
Deletes the current row from the ResultSet object and from the underlying database. This method cannot be called when the cursor is on the insert row.

Throws:
java.sql.SQLException - if a database access error occurs or if this method is called when the cursor is on the insert row

moveToInsertRow

public void moveToInsertRow()
                     throws java.sql.SQLException
Moves the cursor to the insert row. The current cursor position is remembered while the cursor is positioned on the insert row. The insert row is a special row associated with an updatable result set. It is essentially a buffer where a new row may be constructed by calling the updater methods prior to inserting the row into the result set.

Throws:
java.sql.SQLException - if a database access error occurs or the result set is not updatable
See Also:
java.sql.ResultSet.moveToInsertRow()

insertRow

public void insertRow()
               throws java.sql.SQLException
Inserts the contents of the insert row into the ResultSet object and into the database. The cursor must be on the insert row when this method is called.

Throws:
java.sql.SQLException - if a database access error occurs, if this method is called when the cursor is not on the insert row, or if not all of non-nullable columns in the insert row have been given a value

moveToCurrentRow

public void moveToCurrentRow()
                      throws java.sql.SQLException
Moves the cursor to the remembered cursor position, usually the current row. This method has no effect if the cursor is not on the insert row.

Throws:
java.sql.SQLException - if a database access error occurs or the result set is not updatable

refreshRow

public void refreshRow()
                throws java.sql.SQLException
Refreshes the current row with its most recent value in the database. This method cannot be called when the cursor is on the insert row.

Throws:
java.sql.SQLException - if a database access error occurs or if this method is called when the cursor is on the insert row
See Also:
java.sql.ResultSet.refreshRow()

close

public void close()
           throws java.sql.SQLException
Closes the Statement and ResultSet objects and releases the database and JDBC resources asociated with these objects.

Throws:
java.sql.SQLException - if a database access error occurs


Powered by
SourceForge.net Logo