📄 resultset.java
字号:
*/
public InputStream getBinaryStream(int columnIndex) throws java.sql.SQLException
{
byte b[] = getBytes(columnIndex);
if (b != null) {
return new ByteArrayInputStream(b);
}
return null; // SQL NULL
}
/**
* The following routines simply convert the columnName into
* a columnIndex and then call the appropriate routine above.
*
* @param columnName is the SQL name of the column
* @return the column value
* @exception java.sql.SQLException if a database access error occurs
*/
public String getString(String ColumnName) throws java.sql.SQLException
{
return getString(findColumn(ColumnName));
}
public boolean getBoolean(String ColumnName) throws java.sql.SQLException
{
return getBoolean(findColumn(ColumnName));
}
public byte getByte(String ColumnName) throws java.sql.SQLException
{
return getByte(findColumn(ColumnName));
}
public short getShort(String ColumnName) throws java.sql.SQLException
{
return getShort(findColumn(ColumnName));
}
public int getInt(String ColumnName) throws java.sql.SQLException
{
return getInt(findColumn(ColumnName));
}
public long getLong(String ColumnName) throws java.sql.SQLException
{
return getLong(findColumn(ColumnName));
}
public float getFloat(String ColumnName) throws java.sql.SQLException
{
return getFloat(findColumn(ColumnName));
}
public double getDouble(String ColumnName) throws java.sql.SQLException
{
return getDouble(findColumn(ColumnName));
}
public BigDecimal getBigDecimal(String ColumnName, int scale) throws java.sql.SQLException
{
return getBigDecimal(findColumn(ColumnName), scale);
}
public byte[] getBytes(String ColumnName) throws java.sql.SQLException
{
return getBytes(findColumn(ColumnName));
}
public java.sql.Date getDate(String ColumnName) throws java.sql.SQLException
{
return getDate(findColumn(ColumnName));
}
public Time getTime(String ColumnName) throws java.sql.SQLException
{
return getTime(findColumn(ColumnName));
}
public Timestamp getTimestamp(String ColumnName) throws java.sql.SQLException
{
return getTimestamp(findColumn(ColumnName));
}
public InputStream getAsciiStream(String ColumnName) throws java.sql.SQLException
{
return getAsciiStream(findColumn(ColumnName));
}
public InputStream getUnicodeStream(String ColumnName) throws java.sql.SQLException
{
return getUnicodeStream(findColumn(ColumnName));
}
public InputStream getBinaryStream(String ColumnName) throws java.sql.SQLException
{
return getBinaryStream(findColumn(ColumnName));
}
/**
* The first warning reported by calls on this ResultSet is
* returned. Subsequent ResultSet warnings will be chained
* to this java.sql.SQLWarning.
*
* <p>The warning chain is automatically cleared each time a new
* row is read.
*
* <p><B>Note:</B> This warning chain only covers warnings caused by
* ResultSet methods. Any warnings caused by statement methods
* (such as reading OUT parameters) will be chained on the
* Statement object.
*
* @return the first java.sql.SQLWarning or null;
* @exception java.sql.SQLException if a database access error occurs.
*/
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
{
return Warnings;
}
/**
* After this call, getWarnings returns null until a new warning
* is reported for this ResultSet
*
* @exception java.sql.SQLException if a database access error occurs
*/
public void clearWarnings() throws java.sql.SQLException
{
Warnings = null;
}
/**
* Get the name of the SQL cursor used by this ResultSet
*
* <p>In SQL, a result table is retrieved though a cursor that is
* named. The current row of a result can be updated or deleted
* using a positioned update/delete statement that references
* the cursor name.
*
* <p>JDBC supports this SQL feature by providing the name of the
* SQL cursor used by a ResultSet. The current row of a ResulSet
* is also the current row of this SQL cursor.
*
* <p><B>Note:</B> If positioned update is not supported, a java.sql.SQLException
* is thrown.
*
* @return the ResultSet's SQL cursor name.
* @exception java.sql.SQLException if a database access error occurs
*/
public String getCursorName() throws java.sql.SQLException
{
throw new java.sql.SQLException("Positioned Update not supported.", "S1C00");
}
/**
* The numbers, types and properties of a ResultSet's columns are
* provided by the getMetaData method
*
* @return a description of the ResultSet's columns
* @exception java.sql.SQLException if a database access error occurs
*/
public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException
{
return new ResultSetMetaData(Rows, Fields);
}
/**
* Get the value of a column in the current row as a Java object
*
* <p>This method will return the value of the given column as a
* Java object. The type of the Java object will be the default
* Java Object type corresponding to the column's SQL type, following
* the mapping specified in the JDBC specification.
*
* <p>This method may also be used to read database specific abstract
* data types.
*
* @param columnIndex the first column is 1, the second is 2...
* @return a Object holding the column value
* @exception java.sql.SQLException if a database access error occurs
*/
public Object getObject(int columnIndex) throws java.sql.SQLException
{
Field F;
if (columnIndex < 1 || columnIndex > Fields.length) {
throw new java.sql.SQLException("Column index out of range (" + columnIndex + " > " + Fields.length + ").", "S1002");
}
F = Fields[columnIndex - 1];
if (This_Row[columnIndex - 1] == null) {
wasNullFlag = true;
return null;
}
wasNullFlag = false;
switch (F.getSQLType()) {
case Types.BIT:
return new Boolean(getBoolean(columnIndex));
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
return new Integer(getInt(columnIndex));
case Types.BIGINT:
return new Long(getLong(columnIndex));
case Types.DECIMAL:
case Types.NUMERIC:
String S = getString(columnIndex);
BigDecimal Val;
if (S != null) {
if (S.length() == 0) {
Val = new BigDecimal(0);
return Val;
}
try {
Val = new BigDecimal(S);
}
catch (NumberFormatException E) {
throw new java.sql.SQLException ("Bad format for BigDecimal '" + S + "' in column " + columnIndex + "(" + Fields[columnIndex] + ").", "S1009");
}
return Val;
}
else {
return null;
}
case Types.REAL:
case Types.FLOAT:
return new Float(getFloat(columnIndex));
case Types.DOUBLE:
return new Double(getDouble(columnIndex));
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
if (F.isBinary()) {
return getBytes(columnIndex);
}
else {
return getString(columnIndex);
}
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return getBytes(columnIndex);
case Types.DATE:
return getDate(columnIndex);
case Types.TIME:
return getTime(columnIndex);
case Types.TIMESTAMP:
return getTimestamp(columnIndex);
default:
throw new java.sql.SQLException("Unkown type", "S1009");
}
}
/**
* Get the value of a column in the current row as a Java object
*
*<p> This method will return the value of the given column as a
* Java object. The type of the Java object will be the default
* Java Object type corresponding to the column's SQL type, following
* the mapping specified in the JDBC specification.
*
* <p>This method may also be used to read database specific abstract
* data types.
*
* @param columnName is the SQL name of the column
* @return a Object holding the column value
* @exception java.sql.SQLException if a database access error occurs
*/
public Object getObject(String ColumnName) throws java.sql.SQLException
{
return getObject(findColumn(ColumnName));
}
/**
* Map a ResultSet column name to a ResultSet column index
*
* @param columnName the name of the column
* @return the column index
* @exception java.sql.SQLException if a database access error occurs
*/
public int findColumn(String ColumnName) throws java.sql.SQLException
{
int i;
if (Driver.debug) {
System.out.println("Looking for " + ColumnName);
}
for (i = 0 ; i < Fields.length; ++i) {
if (Driver.debug) {
System.out.println(Fields[i].Name);
}
if (Fields[i].Name.equalsIgnoreCase(ColumnName)) {
return (i + 1);
}
String FullName = Fields[i].TableName + "." + Fields[i].Name;
if (FullName.equalsIgnoreCase(ColumnName)) {
return (i + 1);
}
}
throw new java.sql.SQLException ("Column '" + ColumnName + "' not found.", "S0022");
}
// ****************************************************************
//
// END OF PUBLIC INTERFACE
//
// ****************************************************************
/**
* Create a new ResultSet - Note that we create ResultSets to
* represent the results of everything.
*
* @param fields an array of Field objects (basically, the
* ResultSet MetaData)
* @param tuples Vector of the actual data
* @param status the status string returned from the back end
* @param updateCount the number of rows affected by the operation
* @param cursor the positioned update/delete cursor name
*/
ResultSet(Field[] Fields, Vector Tuples, org.gjt.mm.mysql.Connection Conn)
{
this(Fields, Tuples);
setConnection(Conn);
}
ResultSet(Field[] Fields, Vector Tuples)
{
currentRow = -1;
this.Fields = Fields;
Rows = Tuples;
updateCount = (long)Rows.size();
if (Driver.debug)
System.out.println("Retrieved " + updateCount + " rows");
reallyResult = true;
// Check for no results
if (!(Rows.size() == 0)) {
This_Row = (byte[][])Rows.elementAt(0);
if (updateCount == 1) {
boolean nulls = true;
if (This_Row == null) {
nulls = true;
}
else {
for (int i = 0; i < This_Row.length; i++) {
if (This_Row[i] != null) {
nulls = false;
break;
}
}
}
if (nulls) {
currentRow = Tuples.size() + 1;
}
}
}
else {
This_Row = null;
}
}
/**
* Create a result set for an executeUpdate statement.
*
* @param updateCount the number of rows affected by the update
*/
ResultSet(long updateCount, long updateID)
{
this.updateCount = updateCount;
this.updateID = updateID;
reallyResult = false;
Fields = new Field[0];
}
void setConnection(org.gjt.mm.mysql.Connection Conn)
{
this.Conn = Conn;
}
boolean reallyResult()
{
return reallyResult;
}
long getUpdateCount()
{
return updateCount;
}
long getUpdateID()
{
return updateID;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -