📄 resultset.java
字号:
*
* @param columnIndex the column to get the value from
*
* @return the value in the column as a java.io.Reader.
*
* @throws SQLException if an error occurs
*/
public java.io.Reader getCharacterStream(int columnIndex)
throws SQLException {
String stringVal = getString(columnIndex);
if (stringVal != null) {
return new StringReader(stringVal);
} else {
return null;
}
}
/**
* JDBC 2.0
*
* <p>
* Get the value of a column in the current row as a java.io.Reader.
* </p>
*
* @param columnName the column name to retrieve the value from
*
* @return the value as a java.io.Reader
*
* @throws SQLException if an error occurs
*/
public java.io.Reader getCharacterStream(String columnName)
throws SQLException {
return getCharacterStream(findColumn(columnName));
}
/**
* JDBC 2.0 Get a CLOB column.
*
* @param i the first column is 1, the second is 2, ...
*
* @return an object representing a CLOB
*
* @throws SQLException if an error occurs
*/
public java.sql.Clob getClob(int i) throws SQLException {
return new com.mysql.jdbc.Clob(getString(i));
}
/**
* JDBC 2.0 Get a CLOB column.
*
* @param colName the column name
*
* @return an object representing a CLOB
*
* @throws SQLException if an error occurs
*/
public java.sql.Clob getClob(String colName) throws SQLException {
return getClob(findColumn(colName));
}
/**
* JDBC 2.0 Return the concurrency of this result set. The concurrency
* used is determined by the statement that created the result set.
*
* @return the concurrency type, CONCUR_READ_ONLY, etc.
*
* @throws SQLException if a database-access error occurs
*/
public int getConcurrency() throws SQLException {
return (CONCUR_READ_ONLY);
}
/**
* DOCUMENT ME!
*
* @param conn the connection that created this result set.
*/
public void setConnection(com.mysql.jdbc.Connection conn) {
this.connection = conn;
if (this.connection != null) {
this.useStrictFloatingPoint = this.connection.useStrictFloatingPoint();
this.defaultTimeZone = this.connection.getDefaultTimeZone();
} else {
this.defaultTimeZone = TimeZone.getDefault();
}
}
/**
* 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>
*
* <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>
*
* <p>
* <B>Note:</B> If positioned update is not supported, a
* java.sql.SQLException is thrown.
* </p>
*
* @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");
}
/**
* Get the value of a column in the current row as a java.sql.Date object
*
* @param columnIndex the first column is 1, the second is 2...
*
* @return the column value; null if SQL NULL
*
* @exception java.sql.SQLException if a database access error occurs
*/
public java.sql.Date getDate(int columnIndex) throws java.sql.SQLException {
return getDate(columnIndex, null);
}
/**
* DOCUMENT ME!
*
* @param columnName DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws java.sql.SQLException DOCUMENT ME!
*/
public java.sql.Date getDate(String columnName)
throws java.sql.SQLException {
return getDate(findColumn(columnName));
}
/**
* JDBC 2.0 Get the value of a column in the current row as a java.sql.Date
* object. Use the calendar to construct an appropriate millisecond value
* for the Date, if the underlying database doesn't store timezone
* information.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param cal the calendar to use in constructing the date
*
* @return the column value; if the value is SQL NULL, the result is null
*
* @exception SQLException if a database-access error occurs.
* @throws java.sql.SQLException DOCUMENT ME!
*/
public java.sql.Date getDate(int columnIndex, Calendar cal)
throws SQLException {
Integer year = null;
Integer month = null;
Integer day = null;
String stringVal = "";
try {
stringVal = getString(columnIndex);
if (stringVal == null) {
return null;
} else {
int length = stringVal.length();
if ((length > 0) && (stringVal.charAt(0) == '0')
&& (stringVal.equals("0000-00-00")
|| stringVal.equals("0000-00-00 00:00:00")
|| stringVal.equals("00000000000000")
|| stringVal.equals("0"))) {
wasNullFlag = true;
return null;
} else if (fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP) {
// Convert from TIMESTAMP
switch (length) {
case 14:
case 8: {
year = new Integer(stringVal.substring(0, 4));
month = new Integer(stringVal.substring(4, 6));
day = new Integer(stringVal.substring(6, 8));
return fastDateCreate(cal, year.intValue() - 1900,
month.intValue() - 1, day.intValue());
}
case 12:
case 10:
case 6: {
year = new Integer(stringVal.substring(0, 2));
if (year.intValue() <= 69) {
year = new Integer(year.intValue() + 100);
}
month = new Integer(stringVal.substring(2, 4));
day = new Integer(stringVal.substring(4, 6));
return fastDateCreate(cal, year.intValue(),
month.intValue() - 1, day.intValue());
}
case 4: {
year = new Integer(stringVal.substring(0, 4));
if (year.intValue() <= 69) {
year = new Integer(year.intValue() + 100);
}
month = new Integer(stringVal.substring(2, 4));
return fastDateCreate(cal, year.intValue(),
month.intValue() - 1, 1);
}
case 2: {
year = new Integer(stringVal.substring(0, 2));
if (year.intValue() <= 69) {
year = new Integer(year.intValue() + 100);
}
return fastDateCreate(cal, year.intValue(), 0, 1);
}
default:
throw new SQLException("Bad format for Date '"
+ stringVal + "' in column " + columnIndex + "("
+ fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
} /* endswitch */
} else if (fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR) {
year = new Integer(stringVal.substring(0, 4));
return fastDateCreate(cal, year.intValue() - 1900, 0, 1);
} else {
if (length < 10) {
throw new SQLException("Bad format for Date '"
+ stringVal + "' in column " + columnIndex + "("
+ fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
year = new Integer(stringVal.substring(0, 4));
month = new Integer(stringVal.substring(5, 7));
day = new Integer(stringVal.substring(8, 10));
}
return fastDateCreate(cal, year.intValue() - 1900,
month.intValue() - 1, day.intValue());
}
} catch (Exception e) {
throw new java.sql.SQLException("Cannot convert value '"
+ stringVal + "' from column " + columnIndex + "(" + stringVal
+ " ) to DATE.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
/**
* Get the value of a column in the current row as a java.sql.Date object.
* Use the calendar to construct an appropriate millisecond value for the
* Date, if the underlying database doesn't store timezone information.
*
* @param columnName is the SQL name of the column
* @param cal the calendar to use in constructing the date
*
* @return the column value; if the value is SQL NULL, the result is null
*
* @exception SQLException if a database-access error occurs.
*/
public java.sql.Date getDate(String columnName, Calendar cal)
throws SQLException {
return getDate(columnName);
}
/**
* Get the value of a column in the current row as a Java double.
*
* @param columnIndex the first column is 1, the second is 2,...
*
* @return the column value; 0 if SQL NULL
*
* @exception java.sql.SQLException if a database access error occurs
*/
public double getDouble(int columnIndex) throws java.sql.SQLException {
try {
return getDoubleInternal(columnIndex);
} catch (NumberFormatException E) {
throw new java.sql.SQLException("Bad format for number '"
+ new String(thisRow[columnIndex - 1]) + "' in column "
+ columnIndex + "(" + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
/**
* DOCUMENT ME!
*
* @param columnName DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws java.sql.SQLException DOCUMENT ME!
*/
public double getDouble(String columnName) throws java.sql.SQLException {
return getDouble(findColumn(columnName));
}
/**
* JDBC 2.0 Give a hint as to the direction in which the rows in this
* result set will be processed. The initial value is determined by the
* statement that produced the result set. The fetch direction may be
* changed at any time.
*
* @param direction the direction to fetch rows in.
*
* @exception SQLException if a database-access error occurs, or the result
* set type is TYPE_FORWARD_ONLY and direction is not
* FETCH_FORWARD. MM.MySQL actually ignores this, because it
* has the whole result set anyway, so the direction is
* immaterial.
*/
public void setFetchDirection(int direction) throws SQLException {
if ((direction != FETCH_FORWARD) && (direction != FETCH_REVERSE)
&& (direction != FETCH_UNKNOWN)) {
throw new SQLException("Illegal value for fetch direction", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
} else {
fetchDirection = direction;
}
}
/**
* JDBC 2.0 Returns the fetch direction for this result set.
*
* @return the fetch direction for this result set.
*
* @exception SQLException if a database-access error occurs
*/
public int getFetchDirection() throws SQLException {
return fetchDirection;
}
/**
* JDBC 2.0 Give the JDBC driver a hint as to the number of rows that
* should be fetched from the database when more rows are needed for this
* result set. If the fetch size specified is zero, then the JDBC driver
* ignores the value, and is free to make its own best guess as to what
* the fetch size should be. The default value is set by the statement
* that creates the result set. The fetch size may be changed at any
* time.
*
* @param rows the number of rows to fetch
*
* @exception SQLException if a database-access error occurs, or the
* condition 0 <= rows <= this.getMaxRows() is not
* satisfied. Currently ignored by this driver.
*/
public void setFetchSize(int rows) throws SQLException {
if (rows < 0) { /* || rows > getMaxRows()*/
throw new SQLException("Value must be between 0 and getMaxRows()",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
fetchSize = rows;
}
/**
* JDBC 2.0 Return the fetch size for this result set.
*
* @return the fetch size for this result set.
*
* @exception SQLException if a database-access error occurs
*/
public int getFetchSize() throws SQLException {
return fetchSize;
}
/**
* JDBC 2.0
*
* <p>
* Determine if the cursor is on the first row of the result set.
* </p>
*
* @return true if on the first row, false otherwise.
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -