📄 resultset.java
字号:
* @throws NotImplemented DOCUMENT ME! */ public java.sql.Ref getRef(String colName) throws SQLException { throw new NotImplemented(); } /** * JDBC 2.0 * * <p> * Determine the current row number. The first row is number 1, the second * number 2, etc. * </p> * * @return the current row number, else return 0 if there is no current row * * @exception SQLException if a database-access error occurs. */ public int getRow() throws SQLException { if (Driver.TRACE) { Object[] args = { }; Debug.methodCall(this, "getRow", args); } checkClosed(); int currentRow = rowData.getCurrentRowNumber(); int row = 0; // Non-dynamic result sets can be interrogated // for this information if (!rowData.isDynamic()) { if ((currentRow < 0) || rowData.isAfterLast() || rowData.isEmpty()) { row = 0; } else { row = currentRow + 1; } } else { // dynamic (streaming) can not row = currentRow + 1; } if (Driver.TRACE) { Debug.returnValue(this, "getRow", new Integer(row)); } if (Driver.TRACE) { Debug.returnValue(this, "getRow", new Integer(row)); } return row; } /** * Get the value of a column in the current row as a Java short. * * @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 short getShort(int columnIndex) throws java.sql.SQLException { String val = null; try { val = getString(columnIndex); if ((val != null) && (val.length() != 0)) { if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) && (val.indexOf(".") == -1)) { return Short.parseShort(val); } else { // Convert floating point return (short) (Double.parseDouble(val)); } } else { return 0; } } catch (NumberFormatException nfe) { try { // To do: warn on under/overflow? return (short) Double.parseDouble(val); } catch (NumberFormatException newNfe) { ; // ignore, it's not a number } throw new SQLException("Invalid value for getShort() - '" + val + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public short getShort(String columnName) throws java.sql.SQLException { return getShort(findColumn(columnName)); } /** * 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; } /** * Get the value of a column in the current row as a Java String * * @param columnIndex the first column is 1, the second is 2... * * @return the column value, null for SQL NULL * * @exception java.sql.SQLException if a database access error occurs * @throws SQLException DOCUMENT ME! */ public String getString(int columnIndex) throws java.sql.SQLException { checkRowPos(); if (fields == null) { throw new java.sql.SQLException("Query generated no fields for ResultSet", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); } try { if (thisRow[columnIndex - 1] == null) { wasNullFlag = true; return null; } else { wasNullFlag = false; } } catch (NullPointerException E) { wasNullFlag = true; return null; } catch (ArrayIndexOutOfBoundsException aioobEx) { throw new java.sql.SQLException("Column Index out of range ( " + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); } String stringVal = null; columnIndex--; // JDBC is 1-based, Java is not !? if ((connection != null) && connection.useUnicode()) { try { String encoding = this.fields[columnIndex].getCharacterSet(); if (encoding == null) { stringVal = new String(thisRow[columnIndex]); } else { SingleByteCharsetConverter converter = this.connection.getCharsetConverter(encoding); if (converter != null) { stringVal = converter.toString(thisRow[columnIndex]); } else { stringVal = new String(thisRow[columnIndex], encoding); } } } catch (java.io.UnsupportedEncodingException E) { throw new SQLException("Unsupported character encoding '" + connection.getEncoding() + "'.", SQLError.SQL_STATE_GENERAL_ERROR); } } else { stringVal = StringUtils.toAsciiString(thisRow[columnIndex]); } return stringVal; } /** * 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)); } /** * Get the value of a column in the current row as a java.sql.Time object * * @param columnIndex the first column is 1, the second is 2... * * @return the column value; null if SQL NULL * * @throws java.sql.SQLException if a database access error occurs */ public synchronized Time getTime(int columnIndex) throws java.sql.SQLException { return getTimeInternal(columnIndex, this.defaultTimeZone); } /** * Get the value of a column in the current row as a java.sql.Time object. * * @param columnName is the SQL name of the column * * @return the column value; if the value is SQL NULL, the result is null * * @throws java.sql.SQLException if a database-access error occurs. */ public Time getTime(String columnName) throws java.sql.SQLException { return getTime(findColumn(columnName)); } /** * Get the value of a column in the current row as a java.sql.Time object. * Use the calendar to construct an appropriate millisecond value for the * Time, 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 time * * @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.Time getTime(int columnIndex, Calendar cal) throws SQLException { return getTimeInternal(columnIndex, cal.getTimeZone()); } /** * Get the value of a column in the current row as a java.sql.Time object. * Use the calendar to construct an appropriate millisecond value for the * Time, 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 time * * @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.Time getTime(String columnName, Calendar cal) throws SQLException { return getTime(findColumn(columnName), cal); } /** * Get the value of a column in the current row as a java.sql.Timestamp * 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 synchronized Timestamp getTimestamp(int columnIndex) throws java.sql.SQLException { return getTimestampInternal(columnIndex, this.defaultTimeZone); } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public Timestamp getTimestamp(String columnName) throws java.sql.SQLException { return getTimestamp(findColumn(columnName)); } /** * Get the value of a column in the current row as a java.sql.Timestamp * object. Use the calendar to construct an appropriate millisecond value * for the Timestamp, 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 timestamp * * @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.Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { return getTimestampInternal(columnIndex, cal.getTimeZone()); } /** * Get the value of a column in the current row as a java.sql.Timestamp * object. Use the calendar to construct an appropriate millisecond value * for the Timestamp, 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 timestamp * * @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.Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { return getTimestamp(findColumn(columnName), cal); } /** * JDBC 2.0 Return the type of this result set. The type is determined * based on the statement that created the result set. * * @return TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, or * TYPE_SCROLL_SENSITIVE * * @exception SQLException if a database-access error occurs */ public int getType() throws SQLException { return resultSetType; } /** * @see ResultSet#getURL(int) */ public URL getURL(int colIndex) throws SQLException { String val = getString(colIndex); if (val == null) { return null; } else { try { return new URL(val); } catch (MalformedURLException mfe) { throw new SQLException("Malformed URL '" + val + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } } /** * @see ResultSet#getURL(String) */ public URL getURL(String colName) throws SQLException { String val = getString(colName); if (val == null) { return null; } else { try { return new URL(val); } catch (MalformedURLException mfe) { throw new SQLException("Malformed URL '" + val + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); } } } /** * A column value can also be retrieved as a stream of Unicode characters. * We implement this as a binary stream. * * @param columnIndex the first column is 1, the second is 2... * * @return a Java InputStream that delivers the database column value as a * stream of two byte Unicode characters. If the value is SQL * NULL, then the result is null * * @exception java.sql.SQLException if a database access error occurs * * @see getAsciiStream * @see getBinaryStream */ public InputStream getUnicodeStream(int columnIndex) throws java.sql.SQLException { checkRowPos(); return getBinaryStream(columnIndex); } /** * DOCUMENT ME! * * @param columnName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws java.sql.SQLException DOCUMENT ME! */ public InputStream getUnicodeStream(String columnName) throws java.sql.SQLException { return getUnicodeStream(findColumn(columnName)); } /** * The first war
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -