|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.example.project.database.GenericTable
public abstract class GenericTable
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.
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 |
---|
public java.sql.ResultSet resultSet
public java.sql.ResultSet keyResultSet
Constructor Detail |
---|
public GenericTable(java.sql.Connection con)
super( connection )
) with the database connection
object.
con
- database connection.Method Detail |
---|
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)
.
query
- SQL query to execute.
java.sql.SQLException
- if a database access error occurs or the given SQL
statement produces anything other than a single ResultSet object.public void executeQuery(java.lang.String query, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException
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
java.sql.SQLException
- if a database access error occurs or the given SQL
statement produces anything other than a single ResultSet object.public void executeQuery(java.lang.String query, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException
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
java.sql.SQLException
- if a database access error occurs or the given SQL
statement produces anything other than a single ResultSet object.public int executeUpdate(java.lang.String query) throws java.sql.SQLException
query
- the query to execute.
java.sql.SQLException
- if a database access error occurs or the
given SQL statement produces a ResultSet object.public int executeUpdate(java.lang.String query, int autoGeneratedKeys) throws java.sql.SQLException
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
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.public void getGeneratedKeys() throws java.sql.SQLException
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.
java.sql.SQLException
- if a database access error occurs.public void createPreparedStatement(java.lang.String id, java.lang.String query) throws java.sql.SQLException, DuplicateIdentifierException
id
- used to identify this prepared statement.query
- parameterised query that may have one or more '?' parameters.
java.sql.SQLException
- if a database access error occurs.
DuplicateIdentifierException
- if the given ID is a duplicate.public void createPreparedStatement(java.lang.String id, java.lang.String query, int autoGeneratedKeys) throws java.sql.SQLException, DuplicateIdentifierException
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.
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
.
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.public void createPreparedStatement(java.lang.String id, java.lang.String query, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException, DuplicateIdentifierException
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
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.public void createPreparedStatement(java.lang.String id, java.lang.String query, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws java.sql.SQLException, DuplicateIdentifierException
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
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.public void deletePreparedStatement(java.lang.String id)
id
- ID of prepared statement to delete.public void executePreparedQuery(java.lang.String id) throws java.sql.SQLException, UndefinedStatementException
id
- prepared statement ID.
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.public int executePreparedUpdate(java.lang.String id) throws java.sql.SQLException, UndefinedStatementException
id
- prepared statement ID.
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.public void getPreparedGeneratedKeys(java.lang.String id) throws java.sql.SQLException, UndefinedStatementException
executePreparedUpdate(String)
. If this query did not
generate any keys, the keys result set will be populated by an
empty ResultSet
object.
id
- prepared statement ID.
java.sql.SQLException
- if a database access error occurs.
UndefinedStatementException
- if the given ID is not associated with
a prepared statement.public void clearPreparedParameters(java.lang.String id) throws java.sql.SQLException, UndefinedStatementException
id
- identifies the prepared statement to clear the parameters of.
java.sql.SQLException
- if an error occurs during the clear process.
UndefinedStatementException
- if the given ID is not mapped to a
statement.public void setArray(java.lang.String id, int parameterIndex, java.sql.Array x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Array
object.
The driver converts this to an SQL ARRAY
value when it
sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- an Array
object that maps an SQL
ARRAY
value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setAsciiStream(java.lang.String id, int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given input stream, which will
have the specified number of bytes.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the Java input stream that contains the ASCII parameter valuelength
- the number of bytes in the stream
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setAsciiStream(int,InputStream,int)
public void setBigDecimal(java.lang.String id, int parameterIndex, java.math.BigDecimal x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given
java.math.BigDecimal
value. The driver converts this to an
SQL NUMERIC
value when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setBinaryStream(java.lang.String id, int parameterIndex, java.io.InputStream x, int length) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given input stream, which will
have the specified number of bytes.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the java input stream which contains the binary parameter valuelength
- the number of bytes in the stream
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setBinaryStream(int,InputStream,int)
public void setBlob(java.lang.String id, int parameterIndex, java.sql.Blob x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Blob
object.
The driver converts this to an SQL BLOB
value when it
sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- a Blob
object that maps an SQL BLOB
value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setBoolean(java.lang.String id, int parameterIndex, boolean x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java boolean
value. The driver converts this to an SQL BIT
value when
it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setByte(java.lang.String id, int parameterIndex, byte x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java byte
value. The driver converts this to an SQL TINYINT
value
when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setBytes(java.lang.String id, int parameterIndex, byte[] x) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setCharacterStream(java.lang.String id, int parameterIndex, java.io.Reader x, int length) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Reader
object,
which is the given number of characters long.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- java.io.Reader
object that contains the Unicode
datalength
- the number of characters in the stream
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setBinaryStream(int,InputStream,int)
public void setClob(java.lang.String id, int parameterIndex, java.sql.Clob x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Clob
object.
The driver converts this to an SQL CLOB
value when it
sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- a Clob
object that maps an SQL CLOB
value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setDate(java.lang.String id, int parameterIndex, java.sql.Date x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given
java.sql.Date
value. The driver converts this to an SQL
DATE
value when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setDate(java.lang.String id, int parameterIndex, java.sql.Date x, java.util.Calendar cal) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuecal
- the Calendar
object the driver will use to
construct the date
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setDouble(java.lang.String id, int parameterIndex, double x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java double
value. The driver converts this to an SQL DOUBLE
value
when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setFloat(java.lang.String id, int parameterIndex, float x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java float
value. The driver converts this to an SQL FLOAT
value
when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setInt(java.lang.String id, int parameterIndex, int x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java int
value. The driver converts this to an SQL INTEGER
value
when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setLong(java.lang.String id, int parameterIndex, long x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java long
value. The driver converts this to an SQL BIGINT
value
when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic 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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...sqlType
- the SQL type code defined in java.sql.Types
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setNull(java.lang.String id, int parameterIndex, int sqlType, java.lang.String typeName) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- 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
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setNull(int,int,String)
public void setObject(java.lang.String id, int parameterIndex, java.lang.Object x) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setObject(int,Object)
public void setObject(java.lang.String id, int parameterIndex, java.lang.Object x, int targetSqlType) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
with the given object. This method is
like the method setObject below, except that it assumes a scale of zero.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuetargetSqlType
- the SQL type code defined in java.sql.Types
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setObject(int,Object,int)
public void setObject(java.lang.String id, int parameterIndex, java.lang.Object x, int targetSqlType, int scale) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuetargetSqlType
- 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
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementjava.sql.PreparedStatement.setObject(int,Object,int,int)
public void setRef(java.lang.String id, int parameterIndex, java.sql.Ref x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given
REF(<structured-type>)
value. The driver converts
this to an SQL REF
value when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setShort(java.lang.String id, int parameterIndex, short x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given Java
short
value. The driver converts this to an SQL
SMALLINT
value when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setString(java.lang.String id, int parameterIndex, java.lang.String x) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setTime(java.lang.String id, int parameterIndex, java.sql.Time x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given java.sql.Time
value. The driver converts this to an SQL TIME
value when
it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setTime(java.lang.String id, int parameterIndex, java.sql.Time x, java.util.Calendar cal) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuecal
- the Calendar
object the driver will use to
construct the time
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setTimestamp(java.lang.String id, int parameterIndex, java.sql.Timestamp x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given
java.sql.Timestamp
value. The driver converts this to an
SQL TIMESTAMP
value when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setTimestamp(java.lang.String id, int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal) throws java.sql.SQLException, UndefinedStatementException
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.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter valuecal
- the Calendar
object the driver will use to
construct the time
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setURL(java.lang.String id, int parameterIndex, java.net.URL x) throws java.sql.SQLException, UndefinedStatementException
PreparedStatement
to the given
java.net.URL
value. The driver converts this to an SQL
DATALINK
value when it sends it to the database.
id
- PreparedStatement
idparameterIndex
- the first parameter is 1, the second is 2, ...x
- the parameter value
java.sql.SQLException
- if a database access error occurs
UndefinedStatementException
- if the given ID is not mapped to a
statementpublic void setTransactionIsolation(int isolationLevel) throws java.sql.SQLException
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.)
java.sql.SQLException
- if a database access error occurs or the given
parameter is not one of the Connection
constantsjava.sql.Connection.setTransactionIsolation(int)
public int getTransactionIsolation() throws java.sql.SQLException
Connection
object's current transaction
isolation level.
Connection.TRANSACTION_READ_UNCOMMITTED
,
Connection.TRANSACTION_READ_COMMITTED
,
Connection.TRANSACTION_REPEATABLE_READ
,
Connection.TRANSACTION_SERIALIZABLE
, or
Connection.TRANSACTION_NONE
java.sql.SQLException
- if a database access error occurspublic void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
autoCommit
- true
to enable auto-commit mode;
false
to disable it
java.sql.SQLException
- if a database access error occursjava.sql.Connection.setAutoCommit(boolean)
public boolean getAutoCommit() throws java.sql.SQLException
Connection
object.
Connection
object's
auto-commit mode
java.sql.SQLException
- if a database access error occurspublic void commit() throws java.sql.SQLException
Connection
object. This method should be used only when auto-commit mode has been
disabled.
java.sql.SQLException
- if a database access error occurs or the
Connection
object is in auto-commit modepublic void rollback() throws java.sql.SQLException
Connection
object.
This method should be used only when auto-commit mode has been disabled.
java.sql.SQLException
- if a database access error occurs or this
Connection
object is in auto-commit modepublic boolean next() throws java.sql.SQLException
ResultSet
cursor down one row from its
current position. A ResultSet
cursor is initially
positioned before the first row.
true
if the new current row is valid;
false
if there are no more rows
java.sql.SQLException
- if a database access error occurspublic boolean previous() throws java.sql.SQLException
ResultSet
object.
true
if the cursor is on a valid row;
false
if it is off the result set
java.sql.SQLException
- if a database access error occurs or the result
set type is TYPE_FORWARD_ONLY
public boolean first() throws java.sql.SQLException
ResultSet
object.
true
if the cursor is on a valid row;
false
if there are no rows in the result set
java.sql.SQLException
- if a database access error occurs or the result
set type is TYPE_FORWARD_ONLY
public boolean isFirst() throws java.sql.SQLException
ResultSet
object.
true
if the cursor is on the first row;
false
otherwise
java.sql.SQLException
- if a database access error occurspublic boolean last() throws java.sql.SQLException
ResultSet
object.
true
if the cursor is on a valid row;
false
if there are no rows in the result set
java.sql.SQLException
- if a database access error occurs or the result
set type is TYPE_FORWARD_ONLY
public boolean isLast() throws java.sql.SQLException
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.
true
if the cursor is on the last row;
false
otherwise
java.sql.SQLException
- if a database access error occurspublic void beforeFirst() throws java.sql.SQLException
ResultSet
object, just before the first row. This method has no effect if the
result set contains no rows.
java.sql.SQLException
- if a database access error occurs or the result
set type is TYPE_FORWARD_ONLY
public boolean isBeforeFirst() throws java.sql.SQLException
ResultSet
object.
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
java.sql.SQLException
- if a database access error occurspublic void afterLast() throws java.sql.SQLException
ResultSet
object, just after the last row. This method has no effect if the
result set contains no rows.
java.sql.SQLException
- if a database access error occurs or the result
set type is TYPE_FORWARD_ONLY
public boolean isAfterLast() throws java.sql.SQLException
ResultSet
object.
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
java.sql.SQLException
- if a database access error occurspublic void updateRow() throws java.sql.SQLException
ResultSet
object. This method cannot be called
when the cursor is on the insert row.
java.sql.SQLException
- if a database access error occurs or if this method
is called when the cursor is on the insert rowpublic void deleteRow() throws java.sql.SQLException
ResultSet
object and from
the underlying database. This method cannot be called when the cursor
is on the insert row.
java.sql.SQLException
- if a database access error occurs or if this method
is called when the cursor is on the insert rowpublic void moveToInsertRow() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs or the result
set is not updatablejava.sql.ResultSet.moveToInsertRow()
public void insertRow() throws java.sql.SQLException
ResultSet
object and into the database. The cursor must be on the insert row when
this method is called.
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 valuepublic void moveToCurrentRow() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs or the result set
is not updatablepublic void refreshRow() throws java.sql.SQLException
java.sql.SQLException
- if a database access error occurs or if this
method is called when the cursor is on the insert rowjava.sql.ResultSet.refreshRow()
public void close() throws java.sql.SQLException
Statement
and ResultSet
objects
and releases the database and JDBC resources asociated with these
objects.
java.sql.SQLException
- if a database access error occurs
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |