?? resultset.java
字號:
* @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 this.resultSetConcurrency; } /** * DOCUMENT ME! * * @param conn the connection that created this result set. */ public synchronized 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. * * @exception SQLException if a database-access error occurs. */ public boolean isFirst() throws SQLException { if (Driver.TRACE) { Object[] args = { }; Debug.methodCall(this, "isFirst", args); } checkClosed(); boolean b = rowData.isFirst(); if (Driver.TRACE) { Debug.returnValue(this, "isFirst", new Boolean(b)); } return b; } /** * Get the value of a column in the current row as a Java float. * * @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 * @throws SQLException DOCUMENT ME! */ public float getFloat(int columnIndex) throws java.sql.SQLException { String val = null; try { val = getString(columnIndex); if ((val != null) && (val.length() != 0)) { float f = Float.parseFloat(val); return f; } else { return 0; } } catch (NumberFormatException nfe) { try { // To do: warn on under/overflow? return (float) Double.parseDouble(val); } catch (NumberFormatException newNfe) { ; // ignore, it's not a number } throw new SQLException("Invalid value for getFloat() - '" + val + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -