📄 resultsetdb.java
字号:
package org.trinet.jdbc;
import org.trinet.jdbc.datatypes.*;
import java.sql.*;
/** Wrapper around a JDBC ResultSet interface to provide methods for creating org.trinet.jdbc.datatypes.DataObjects
* from parsing the ResultSet column data. As with ResultSet objects column index references begin at 1, not 0.
* Used by NCEDC schema table class DataTableRow.
* @see org.trinet.jdbc.table.DataTableRow
*/
public class ResultSetDb {
/** Handle to ResultSet object */
ResultSet rs;
/** Default constructor intializes a null ResultSet. */
public ResultSetDb() {rs = null;}
/** Initializes this object with the specified JDBC ResultSet, presumably returned from a databasae table query. */
public ResultSetDb(ResultSet rs) { this.rs = rs; }
/** Set the alias to the handle of JDBC ResultSet used by this object. */
public void setResultSet(ResultSet rs) {
this.rs = rs;
}
/** Returns the alias handle of the JDBC ResultSet used by this object. */
public ResultSet getResultSet() {
return rs;
}
/** If ResultSet object for specified column name is null, returns "NULL". */
public String getStringNull(String colName) throws SQLException {
String str = rs.getString(colName);
if (str == null) return NullValueDb.NULL_STRING;
return str;
}
/** If ResultSet object at specified column index is null, returns "NULL". */
public String getStringNull(int colNumber) throws SQLException {
String str = rs.getString(colNumber);
if (str == null) return NullValueDb.NULL_STRING;
return str;
}
/** If ResultSet object for specified column name is null, returns "". */
public String getStringEmpty(String colName) throws SQLException {
String str = rs.getString(colName);
if (str == null) return "";
return str;
}
/** If ResultSet object at specified column index is null, returns "". */
public String getStringEmpty(int colNumber) throws SQLException {
String str = rs.getString(colNumber);
if (str == null) return "";
return str;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column name.
* If ResultSet object for specified column name is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataInteger
*/
public DataInteger getDataInteger(String colName) throws SQLException {
DataInteger value = new DataInteger(rs.getInt(colName));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_INT);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column index.
* If ResultSet object for specified column index is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataInteger
*/
public DataInteger getDataInteger(int colNumber) throws SQLException {
DataInteger value = new DataInteger(rs.getInt(colNumber));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_INT);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column name.
* If ResultSet object for specified column name is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataLong
*/
public DataLong getDataLong(String colName) throws SQLException {
DataLong value = new DataLong(rs.getLong(colName));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_LONG);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column index.
* If ResultSet object for specified column index is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataLong
*/
public DataLong getDataLong(int colNumber) throws SQLException {
DataLong value = new DataLong(rs.getLong(colNumber));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_LONG);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column name.
* If ResultSet object for specified column name is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataFloat
*/
public DataFloat getDataFloat(String colName) throws SQLException {
DataFloat value = new DataFloat(rs.getFloat(colName));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_FLOAT);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column index.
* If ResultSet object for specified column index is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataFloat
*/
public DataFloat getDataFloat(int colNumber) throws SQLException {
DataFloat value = new DataFloat(rs.getFloat(colNumber));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_FLOAT);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column name.
* If ResultSet object for specified column name is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataDouble
*/
public DataDouble getDataDouble(String colName) throws SQLException {
DataDouble value = new DataDouble(rs.getDouble(colName));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_DOUBLE);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column index.
* If ResultSet object for specified column index is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataDouble
*/
public DataDouble getDataDouble(int colNumber) throws SQLException {
DataDouble value = new DataDouble(rs.getDouble(colNumber));
if (rs.wasNull()) {
value.setValue(NullValueDb.NULL_DOUBLE);
value.setNull(true);
}
value.setUpdate(false);
return value;
}
/** Returns a new DataObject whose value is set to that found in the ResultSet for the specified column name.
* If ResultSet object for specified column name is null, returns NullValueDb.NULL_xxx for the contained value type.
* and sets the state flags isNull() == true and isUpdate() == true.
* @see org.trinet.jdbc.NullValueDb
* @see org.trinet.jdbc.datatypes.DataObject
* @see org.trinet.jdbc.datatypes.DataBoolean
*/
public DataBoolean getDataBoolean(String colName) throws SQLException {
DataBoolean value = new DataBoolean(rs.getBoolean(colName));
if (rs.wasNull()) {
value.setValue(false);
value.setNull(true);
}
value.setUpdate(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -