📄 resultset.java
字号:
* JDBC 2.0
*
* Update the underlying database with the new contents of the
* current row. Cannot be called when on the insert row.
*
* @exception SQLException if a database-access error occurs, or
* if called when on the insert row
*/
public void updateRow() throws SQLException {
if (!_updatable) {
throw new SQLException(UPDATEABLE_MESSAGE, "S1000");
}
if (_doing_updates) {
_Updater.executeUpdate();
//int num_fields = Fields.length;
//for (int i = 0; i < num_fields; i++) {
// if (_Updater.isNull(i)) {
// System.out.println("isNull(" + i + ") = true");
// This_Row[i] = null;
// }
// else {
// System.out.println("_Updater.getBytes(i) = " + new String(_Updater.getBytes(i)));
//
// This_Row[i] = _Updater.getBytes(i);
// }
//}
refreshRow();
_doing_updates = false;
}
//
// fixes calling updateRow() and then doing more
// updates on same row...
syncUpdate();
}
/**
* JDBC 2.0
*
* Delete the current row from the result set and the underlying
* database. Cannot be called when on the insert row.
*
* @exception SQLException if a database-access error occurs, or if
* called when on the insert row.
*/
public void deleteRow() throws SQLException {
if (!_updatable) {
throw new SQLException(UPDATEABLE_MESSAGE, "S1000");
}
if (_on_insert_row) {
throw new SQLException("Can not call deleteRow() when on insert row");
}
else
if (_rows.size() == 0) {
throw new SQLException("Can't deleteRow() on empty result set");
}
else
if (isBeforeFirst()) {
throw new SQLException("Before start of result set. Can not call deleteRow().");
}
else
if (isAfterLast()) {
throw new SQLException("After end of result set. Can not call deleteRow().");
}
if (_Deleter == null) {
if (_DeleteSQL == null) {
generateStatements();
}
_Deleter =
(com.mysql.jdbc.jdbc2.PreparedStatement) _connection.prepareStatement(_DeleteSQL);
}
_Deleter.clearParameters();
String Encoding = null;
if (_connection.useUnicode()) {
Encoding = _connection.getEncoding();
}
try {
int num_keys = _PrimaryKeyIndicies.size();
if (num_keys == 1) {
int index = ((Integer) _PrimaryKeyIndicies.elementAt(0)).intValue();
String CurrentVal =
(Encoding == null
? new String(_thisRow[index])
: new String(_thisRow[index], Encoding));
_Deleter.setString(1, CurrentVal);
}
else {
for (int i = 0; i < num_keys; i++) {
int index = ((Integer) _PrimaryKeyIndicies.elementAt(i)).intValue();
String CurrentVal =
(Encoding == null
? new String(_thisRow[index])
: new String(_thisRow[index], Encoding));
_Deleter.setString(i + 1, CurrentVal);
}
}
_Deleter.executeUpdate();
_rows.removeElementAt(_currentRow);
}
catch (java.io.UnsupportedEncodingException UE) {
throw new SQLException(
"Unsupported character encoding '" + _connection.getEncoding() + "'");
}
}
/**
* JDBC 2.0
*
* Refresh the value of the current row with its current value in
* the database. Cannot be called when on the insert row.
*
* The refreshRow() method provides a way for an application to
* explicitly tell the JDBC driver to refetch a row(s) from the
* database. An application may want to call refreshRow() when
* caching or prefetching is being done by the JDBC driver to
* fetch the latest value of a row from the database. The JDBC driver
* may actually refresh multiple rows at once if the fetch size is
* greater than one.
*
* All values are refetched subject to the transaction isolation
* level and cursor sensitivity. If refreshRow() is called after
* calling updateXXX(), but before calling updateRow() then the
* updates made to the row are lost. Calling refreshRow() frequently
* will likely slow performance.
*
* @exception SQLException if a database-access error occurs, or if
* called when on the insert row.
*/
public void refreshRow() throws SQLException {
if (!_updatable) {
throw new SQLException(UPDATEABLE_MESSAGE, "S1000");
}
if (_on_insert_row) {
throw new SQLException("Can not call refreshRow() when on insert row");
}
else
if (_rows.size() == 0) {
throw new SQLException("Can't refreshRow() on empty result set");
}
else
if (isBeforeFirst()) {
throw new SQLException("Before start of result set. Can not call refreshRow().");
}
else
if (isAfterLast()) {
throw new SQLException("After end of result set. Can not call refreshRow().");
}
if (_Refresher == null) {
if (_RefreshSQL == null) {
generateStatements();
}
_Refresher =
(com.mysql.jdbc.jdbc2.PreparedStatement) _connection.prepareStatement(_RefreshSQL);
}
_Refresher.clearParameters();
String Encoding = null;
if (_connection.useUnicode()) {
Encoding = _connection.getEncoding();
}
try {
int num_keys = _PrimaryKeyIndicies.size();
if (num_keys == 1) {
int index = ((Integer) _PrimaryKeyIndicies.elementAt(0)).intValue();
String CurrentVal =
(Encoding == null
? new String(_thisRow[index])
: new String(_thisRow[index], Encoding));
_Refresher.setString(1, CurrentVal);
}
else {
for (int i = 0; i < num_keys; i++) {
int index = ((Integer) _PrimaryKeyIndicies.elementAt(i)).intValue();
String CurrentVal =
(Encoding == null
? new String(_thisRow[index])
: new String(_thisRow[index], Encoding));
_Refresher.setString(i + 1, CurrentVal);
}
}
java.sql.ResultSet rs = null;
try
{
rs = _Refresher.executeQuery();
int numCols = rs.getMetaData().getColumnCount();
if (rs.next())
{
for (int i = 0; i < numCols; i++)
{
byte[] val = rs.getBytes(i + 1);
if (val == null || rs.wasNull())
{
_thisRow[i] = null;
}
else
{
_thisRow[i] = rs.getBytes(i + 1);
}
}
}
else
{
throw new SQLException("refreshRow() called on row that has been deleted or had primary key changed", "S1000");
}
}
finally
{
if (rs != null)
{
try
{
rs.close();
}
catch (Exception ex) {}
}
}
}
catch (java.io.UnsupportedEncodingException UE) {
throw new SQLException(
"Unsupported character encoding '" + _connection.getEncoding() + "'");
}
}
/**
* JDBC 2.0
*
* The cancelRowUpdates() method may be called after calling an
* updateXXX() method(s) and before calling updateRow() to rollback
* the updates made to a row. If no updates have been made or
* updateRow() has already been called, then this method has no
* effect.
*
* @exception SQLException if a database-access error occurs, or if
* called when on the insert row.
*
*/
public void cancelRowUpdates() throws SQLException {
if (_doing_updates) {
_doing_updates = false;
_Updater.clearParameters();
}
}
/**
* JDBC 2.0
*
* Move 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 updateXXX() methods prior to
* inserting the row into the result set.
*
* Only the updateXXX(), getXXX(), and insertRow() methods may be
* called when the cursor is on the insert row. All of the columns in
* a result set must be given a value each time this method is
* called before calling insertRow(). UpdateXXX()must be called before
* getXXX() on a column.
*
* @exception SQLException if a database-access error occurs,
* or the result set is not updatable
*/
public void moveToInsertRow() throws SQLException {
if (!_updatable) {
throw new SQLException(UPDATEABLE_MESSAGE, "S1000");
}
if (_Inserter == null) {
generateStatements();
_Inserter =
(com.mysql.jdbc.jdbc2.PreparedStatement) _connection.prepareStatement(_InsertSQL);
resetInserter();
}
else {
resetInserter();
}
_on_insert_row = true;
_doing_updates = false;
}
/**
* JDBC 2.0
*
* Move the cursor to the remembered cursor position, usually the
* current row. Has no effect unless the cursor is on the insert
* row.
*
* @exception SQLException if a database-access error occurs,
* or the result set is not updatable
*/
public void moveToCurrentRow() throws SQLException {
if (!_updatable) {
throw new SQLException(UPDATEABLE_MESSAGE, "S1000");
}
_on_insert_row = false;
}
/**
* JDBC 2.0
*
* Return the Statement that produced the ResultSet.
*
* @return the Statment that produced the result set, or
* null if the result was produced some other way.
* @exception SQLException if a database-access error occurs
*/
public java.sql.Statement getStatement() throws SQLException {
return (java.sql.Statement) _owningStatement;
}
/**
* JDBC 2.0
*
* Returns the value of column @i as a Java object. Use the
* @map to determine the class from which to construct data of
* SQL structured and distinct types.
*
* @param i the first column is 1, the second is 2, ...
* @param map the mapping from SQL type names to Java classes
* @return an object representing the SQL value
*/
public Object getObject(int i, java.util.Map map) throws SQLException {
throw new NotImplemented();
}
/**
* JDBC 2.0
*
* Get a REF(<structured-type>) column.
*
* @param i the first column is 1, the second is 2, ...
* @return an object representing data of an SQL REF type
*/
public java.sql.Ref getRef(int i) throws SQLException {
throw new NotImplemented();
}
/**
* JDBC 2.0
*
* Get a BLOB column.
*
* @param i the first column is 1, the second is 2, ...
* @return an object representing a BLOB
*/
public java.sql.Blob getBlob(int columnIndex) throws SQLException {
checkRowPos();
if (columnIndex < 1 || columnIndex > _fields.length) {
throw new java.sql.SQLException(
"Column Index out of range ( " + columnIndex + " > " + _fields.length + ").",
"S1002");
}
try {
if (_thisRow[columnIndex - 1] == null) {
_wasNullFlag = true;
}
else {
_wasNullFlag = false;
}
}
catch (NullPointerException E) {
_wasNullFlag = true;
}
if (_wasNullFlag) {
return null;
}
return new Blob(_thisRow[columnIndex - 1]);
}
/**
* JDBC 2.0
*
* Get a CLOB column.
*
* @param i the first column is 1, the second is 2, ...
* @return an object representing a CLOB
*/
public java.sql.Clob getClob(int i) throws SQLException {
throw new NotImplemented();
}
/**
* JDBC 2.0
*
* Get an array column.
*
* @param i the first column is 1, the second is 2, ...
* @return an object representing an SQL array
*/
public java.sql.Array getArray(int i) throws SQLException {
throw new NotImplemented();
}
/**
* JDBC 2.0
*
* Returns the value of column @i as a Java object. Use the
* @map to determine the class from which to construct data of
* SQL structured and distinct types.
*
* @param colName the column name
* @param map the mapping from SQL type names to Java classes
* @return an object representing the SQL value
*/
public Object getObject(String colName, java.util.Map map)
throws SQLException {
throw new NotImplemented();
}
/**
* JDBC 2.0
*
* Get a REF(<structured-type>) column.
*
* @param colName the column name
* @return an object representing data of an SQL REF type
*/
public java.sql.Ref getRef(String colName) throws SQLException {
throw new NotImplemented();
}
/**
* JDBC 2.0
*
* Get a BLOB column.
*
* @param colName the column name
* @return an object representing a BLOB
*/
public java.sql.Blob getBlob(S
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -