ResultSet.java
资源名称:bookshop.zip [点击查看]
上传用户:sxlinghang
上传日期:2022-07-20
资源大小:1405k
文件大小:140k
源码类别:
数据库编程
开发平台:
Java
- /*
- Copyright (C) 2002 MySQL AB
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- package com.mysql.jdbc;
- import java.io.ByteArrayInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.StringReader;
- import java.math.BigDecimal;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.sql.Array;
- import java.sql.Date;
- import java.sql.Ref;
- import java.sql.SQLException;
- import java.sql.SQLWarning;
- import java.sql.Time;
- import java.sql.Timestamp;
- import java.sql.Types;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.TimeZone;
- /**
- * A ResultSet provides access to a table of data generated by executing a
- * Statement. The table rows are retrieved in sequence. Within a row its
- * column values can be accessed in any order.
- *
- * <P>
- * A ResultSet maintains a cursor pointing to its current row of data.
- * Initially the cursor is positioned before the first row. The 'next' method
- * moves the cursor to the next row.
- * </p>
- *
- * <P>
- * The getXXX methods retrieve column values for the current row. You can
- * retrieve values either using the index number of the column, or by using
- * the name of the column. In general using the column index will be more
- * efficient. Columns are numbered from 1.
- * </p>
- *
- * <P>
- * For maximum portability, ResultSet columns within each row should be read in
- * left-to-right order and each column should be read only once.
- * </p>
- *
- * <P>
- * For the getXXX methods, the JDBC driver attempts to convert the underlying
- * data to the specified Java type and returns a suitable Java value. See the
- * JDBC specification for allowable mappings from SQL types to Java types with
- * the ResultSet getXXX methods.
- * </p>
- *
- * <P>
- * Column names used as input to getXXX methods are case insenstive. When
- * performing a getXXX using a column name, if several columns have the same
- * name, then the value of the first matching column will be returned. The
- * column name option is designed to be used when column names are used in the
- * SQL Query. For columns that are NOT explicitly named in the query, it is
- * best to use column numbers. If column names were used there is no way for
- * the programmer to guarentee that they actually refer to the intended
- * columns.
- * </p>
- *
- * <P>
- * A ResultSet is automatically closed by the Statement that generated it when
- * that Statement is closed, re-executed, or is used to retrieve the next
- * result from a sequence of multiple results.
- * </p>
- *
- * <P>
- * The number, types and properties of a ResultSet's columns are provided by
- * the ResultSetMetaData object returned by the getMetaData method.
- * </p>
- *
- * @author Mark Matthews
- * @version $Id: ResultSet.java,v 1.18.2.25 2004/02/06 00:55:37 mmatthew Exp $
- *
- * @see ResultSetMetaData
- * @see java.sql.ResultSet
- */
- public class ResultSet implements java.sql.ResultSet {
- /**
- * This method ends up being staticly synchronized, so just store our own
- * copy....
- */
- private TimeZone defaultTimeZone;
- /** The Connection instance that created us */
- protected com.mysql.jdbc.Connection connection; // The connection that created us
- /** Map column names (and all of their permutations) to column indices */
- protected Map columnNameToIndex = null;
- /** Map of fully-specified column names to column indices */
- protected Map fullColumnNameToIndex = null;
- /** The actual rows */
- protected RowData rowData; // The results
- /** The warning chain */
- protected java.sql.SQLWarning warningChain = null;
- /** The statement that created us */
- protected com.mysql.jdbc.Statement owningStatement;
- /** The catalog that was in use when we were created */
- protected String catalog = null;
- /**
- * Any info message from the server that was created while generating this
- * result set (if 'info parsing' is enabled for the connection).
- */
- protected String serverInfo = null;
- /** The fields for this result set */
- protected Field[] fields; // The fields
- /** Pointer to current row data */
- protected byte[][] thisRow; // Values for current row
- /** Are we in the middle of doing updates to the current row? */
- protected boolean doingUpdates = false;
- /** Has this result set been closed? */
- protected boolean isClosed = false;
- /** Are we on the insert row? */
- protected boolean onInsertRow = false;
- /**
- * Do we actually contain rows, or just information about
- * UPDATE/INSERT/DELETE?
- */
- protected boolean reallyResult = false;
- /** Did the previous value retrieval find a NULL? */
- protected boolean wasNullFlag = false;
- /**
- * First character of the query that created this result set...Used to
- * determine whether or not to parse server info messages in certain
- * circumstances.
- */
- protected char firstCharOfQuery;
- /** The current row #, -1 == before start of result set */
- protected int currentRow = -1; // Cursor to current row;
- /** The direction to fetch rows (always FETCH_FORWARD) */
- protected int fetchDirection = FETCH_FORWARD;
- /** The number of rows to fetch in one go... */
- protected int fetchSize = 0;
- /** Are we read-only or updatable? */
- protected int resultSetConcurrency = 0;
- /** Are we scroll-sensitive/insensitive? */
- protected int resultSetType = 0;
- /** How many rows were affected by UPDATE/INSERT/DELETE? */
- protected long updateCount;
- // These are longs for
- // recent versions of the MySQL server.
- //
- // They get reduced to ints via the JDBC API,
- // but can be retrieved through a MySQLStatement
- // in their entirety.
- //
- /** Value generated for AUTO_INCREMENT columns */
- protected long updateId = -1;
- private Calendar fastDateCal = null;
- private boolean hasBuiltIndexMapping = false;
- private boolean useStrictFloatingPoint = false;
- /**
- * Create a result set for an executeUpdate statement.
- *
- * @param updateCount the number of rows affected by the update
- * @param updateID the autoincrement value (if any)
- */
- public ResultSet(long updateCount, long updateID) {
- this.updateCount = updateCount;
- this.updateId = updateID;
- reallyResult = false;
- fields = new Field[0];
- }
- /**
- * Create a new ResultSet
- *
- * @param catalog the database in use when we were created
- * @param fields an array of Field objects (basically, the ResultSet
- * MetaData)
- * @param tuples actual row data
- * @param conn the Connection that created us.
- *
- * @throws SQLException if an error occurs
- */
- public ResultSet(String catalog, Field[] fields, RowData tuples,
- com.mysql.jdbc.Connection conn) throws SQLException {
- this(fields, tuples);
- setConnection(conn);
- this.catalog = catalog;
- }
- /**
- * Creates a new ResultSet object.
- *
- * @param fields DOCUMENT ME!
- * @param tuples DOCUMENT ME!
- *
- * @throws SQLException DOCUMENT ME!
- */
- public ResultSet(Field[] fields, RowData tuples) throws SQLException {
- //_currentRow = -1;
- this.fields = fields;
- this.rowData = tuples;
- this.updateCount = (long) rowData.size();
- if (Driver.DEBUG) {
- System.out.println("Retrieved " + updateCount + " rows");
- }
- this.reallyResult = true;
- // Check for no results
- if (this.rowData.size() > 0) {
- //_thisRow = _rows.next();
- if (this.updateCount == 1) {
- if (this.thisRow == null) {
- //_currentRow = -1;
- this.rowData.close(); // empty result set
- this.updateCount = -1;
- }
- }
- } else {
- this.thisRow = null;
- }
- this.rowData.setOwner(this);
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Determine if the cursor is after the last row in the result set.
- * </p>
- *
- * @return true if after the last row, false otherwise. Returns false when
- * the result set contains no rows.
- *
- * @exception SQLException if a database-access error occurs.
- */
- public boolean isAfterLast() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "isAfterLast", args);
- }
- boolean b = rowData.isAfterLast();
- if (Driver.TRACE) {
- Debug.returnValue(this, "isAfterLast", new Boolean(b));
- }
- return b;
- }
- /**
- * JDBC 2.0 Get an array column.
- *
- * @param i the first column is 1, the second is 2, ...
- *
- * @return an object representing an SQL array
- *
- * @throws SQLException if a database error occurs
- * @throws NotImplemented DOCUMENT ME!
- */
- public java.sql.Array getArray(int i) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * JDBC 2.0 Get an array column.
- *
- * @param colName the column name
- *
- * @return an object representing an SQL array
- *
- * @throws SQLException if a database error occurs
- * @throws NotImplemented DOCUMENT ME!
- */
- public java.sql.Array getArray(String colName) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * A column value can be retrieved as a stream of ASCII characters and then
- * read in chunks from the stream. This method is particulary suitable
- * for retrieving large LONGVARCHAR values. The JDBC driver will do any
- * necessary conversion from the database format into ASCII.
- *
- * <p>
- * <B>Note:</B> All the data in the returned stream must be read prior to
- * getting the value of any other column. The next call to a get method
- * implicitly closes the stream. Also, a stream may return 0 for
- * available() whether there is data available or not.
- * </p>
- *
- * @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 one byte ASCII characters. If the value is SQL NULL
- * then the result is null
- *
- * @exception java.sql.SQLException if a database access error occurs
- *
- * @see getBinaryStream
- */
- public InputStream getAsciiStream(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 getAsciiStream(String columnName)
- throws java.sql.SQLException {
- return getAsciiStream(findColumn(columnName));
- }
- //---------------------------------------------------------------------
- // Traversal/Positioning
- //---------------------------------------------------------------------
- /**
- * JDBC 2.0
- *
- * <p>
- * Determine if the cursor is before the first row in the result set.
- * </p>
- *
- * @return true if before the first row, false otherwise. Returns false
- * when the result set contains no rows.
- *
- * @exception SQLException if a database-access error occurs.
- */
- public boolean isBeforeFirst() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "isBeforeFirst", args);
- }
- boolean b = rowData.isBeforeFirst();
- if (Driver.TRACE) {
- Debug.returnValue(this, "isBeforeFirst", new Boolean(b));
- }
- return b;
- }
- /**
- * Get the value of a column in the current row as a java.math.BigDecimal
- * object
- *
- * @param columnIndex the first column is 1, the second is 2...
- * @param scale the number of digits to the right of the decimal
- *
- * @return the column value; if the value is SQL NULL, null
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public BigDecimal getBigDecimal(int columnIndex, int scale)
- throws java.sql.SQLException {
- String stringVal = getString(columnIndex);
- BigDecimal val;
- if (stringVal != null) {
- if (stringVal.length() == 0) {
- val = new BigDecimal(0);
- return val.setScale(scale);
- }
- try {
- val = new BigDecimal(stringVal);
- } catch (NumberFormatException ex) {
- throw new java.sql.SQLException("Bad format for BigDecimal '"
- + stringVal + "' in column " + columnIndex + "("
- + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- try {
- return val.setScale(scale);
- } catch (ArithmeticException ex) {
- throw new java.sql.SQLException("Bad format for BigDecimal '"
- + stringVal + "' in column " + columnIndex + "("
- + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- return null;
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- * @param scale DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public BigDecimal getBigDecimal(String columnName, int scale)
- throws java.sql.SQLException {
- return getBigDecimal(findColumn(columnName), scale);
- }
- /**
- * JDBC 2.0 Get the value of a column in the current row as a
- * java.math.BigDecimal object.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- *
- * @return the column value (full precision); 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 BigDecimal getBigDecimal(int columnIndex) throws SQLException {
- String stringVal = getString(columnIndex);
- BigDecimal val;
- if (stringVal != null) {
- if (stringVal.length() == 0) {
- val = new BigDecimal(0);
- return val;
- }
- try {
- val = new BigDecimal(stringVal);
- return val;
- } catch (NumberFormatException ex) {
- throw new java.sql.SQLException("Bad format for BigDecimal '"
- + stringVal + "' in column " + columnIndex + "("
- + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- return null;
- }
- /**
- * JDBC 2.0 Get the value of a column in the current row as a
- * java.math.BigDecimal object.
- *
- * @param columnName the name of the column to retrieve the value from
- *
- * @return the BigDecimal value in the column
- *
- * @throws SQLException if an error occurs
- */
- public BigDecimal getBigDecimal(String columnName)
- throws SQLException {
- return getBigDecimal(findColumn(columnName));
- }
- /**
- * A column value can also be retrieved as a binary strea. This method is
- * suitable for retrieving LONGVARBINARY values.
- *
- * @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 bytes. If the value is SQL NULL, then the result is
- * null
- *
- * @exception java.sql.SQLException if a database access error occurs
- *
- * @see getAsciiStream
- * @see getUnicodeStream
- */
- public InputStream getBinaryStream(int columnIndex)
- throws java.sql.SQLException {
- checkRowPos();
- byte[] b = getBytes(columnIndex);
- if (b != null) {
- return new ByteArrayInputStream(b);
- }
- return null;
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public InputStream getBinaryStream(String columnName)
- throws java.sql.SQLException {
- return getBinaryStream(findColumn(columnName));
- }
- /**
- * JDBC 2.0 Get a BLOB column.
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- *
- * @return an object representing a BLOB
- *
- * @throws SQLException if an error occurs.
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public java.sql.Blob getBlob(int columnIndex) throws SQLException {
- checkRowPos();
- if ((columnIndex < 1) || (columnIndex > fields.length)) {
- throw new java.sql.SQLException("Column Index out of range ( "
- + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER);
- }
- try {
- if (thisRow[columnIndex - 1] == null) {
- wasNullFlag = true;
- } else {
- wasNullFlag = false;
- }
- } catch (NullPointerException ex) {
- wasNullFlag = true;
- }
- if (wasNullFlag) {
- return null;
- }
- return new Blob(thisRow[columnIndex - 1]);
- }
- /**
- * JDBC 2.0 Get a BLOB column.
- *
- * @param colName the column name
- *
- * @return an object representing a BLOB
- *
- * @throws SQLException if an error occurs.
- */
- public java.sql.Blob getBlob(String colName) throws SQLException {
- return getBlob(findColumn(colName));
- }
- /**
- * Get the value of a column in the current row as a Java boolean
- *
- * @param columnIndex the first column is 1, the second is 2...
- *
- * @return the column value, false for SQL NULL
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public boolean getBoolean(int columnIndex) throws java.sql.SQLException {
- String stringVal = getString(columnIndex);
- if ((stringVal != null) && (stringVal.length() > 0)) {
- int c = Character.toLowerCase(stringVal.charAt(0));
- return ((c == 't') || (c == 'y') || (c == '1')
- || stringVal.equals("-1"));
- }
- return false;
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public boolean getBoolean(String columnName) throws java.sql.SQLException {
- return getBoolean(findColumn(columnName));
- }
- /**
- * Get the value of a column in the current row as a Java byte.
- *
- * @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 byte getByte(int columnIndex) throws java.sql.SQLException {
- checkRowPos();
- try {
- if (thisRow[columnIndex - 1] == null) {
- wasNullFlag = true;
- } else {
- wasNullFlag = false;
- }
- } catch (NullPointerException E) {
- wasNullFlag = true;
- }
- if (wasNullFlag) {
- return 0;
- }
- Field field = fields[columnIndex - 1];
- switch (field.getMysqlType()) {
- case MysqlDefs.FIELD_TYPE_DECIMAL:
- case MysqlDefs.FIELD_TYPE_TINY:
- case MysqlDefs.FIELD_TYPE_SHORT:
- case MysqlDefs.FIELD_TYPE_LONG:
- case MysqlDefs.FIELD_TYPE_FLOAT:
- case MysqlDefs.FIELD_TYPE_DOUBLE:
- case MysqlDefs.FIELD_TYPE_LONGLONG:
- case MysqlDefs.FIELD_TYPE_INT24:
- try {
- String stringVal = getString(columnIndex);
- int decimalIndex = stringVal.indexOf(".");
- // Strip off the decimals
- if (decimalIndex != -1) {
- stringVal = stringVal.substring(0, decimalIndex);
- }
- return Byte.parseByte(stringVal);
- } catch (NumberFormatException NFE) {
- throw new SQLException("Value '" + getString(columnIndex)
- + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- default:
- try {
- String stringVal = getString(columnIndex);
- int decimalIndex = stringVal.indexOf(".");
- // Strip off the decimals
- if (decimalIndex != -1) {
- stringVal = stringVal.substring(0, decimalIndex);
- }
- return Byte.parseByte(stringVal);
- } catch (NumberFormatException NFE) {
- throw new SQLException("Value '" + getString(columnIndex)
- + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- // FIXME: JDBC-Compliance test is broken, wants to convert string->byte(num)
- //return _thisRow[columnIndex - 1][0];
- }
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public byte getByte(String columnName) throws java.sql.SQLException {
- return getByte(findColumn(columnName));
- }
- /**
- * Get the value of a column in the current row as a Java byte array.
- *
- * <p>
- * <b>Be warned</b> If the blob is huge, then you may run out of memory.
- * </p>
- *
- * @param columnIndex the first column is 1, the second is 2, ...
- *
- * @return the column value; if the value is SQL NULL, the result is null
- *
- * @exception java.sql.SQLException if a database access error occurs
- */
- public byte[] getBytes(int columnIndex) throws java.sql.SQLException {
- checkRowPos();
- try {
- if (thisRow[columnIndex - 1] == null) {
- wasNullFlag = true;
- } else {
- wasNullFlag = false;
- }
- } catch (NullPointerException E) {
- wasNullFlag = true;
- } catch (ArrayIndexOutOfBoundsException aioobEx) {
- throw new java.sql.SQLException("Column Index out of range ( "
- + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER);
- }
- if (wasNullFlag) {
- return null;
- } else {
- return thisRow[columnIndex - 1];
- }
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public byte[] getBytes(String columnName) throws java.sql.SQLException {
- return getBytes(findColumn(columnName));
- }
- //--------------------------JDBC 2.0-----------------------------------
- //---------------------------------------------------------------------
- // Getter's and Setter's
- //---------------------------------------------------------------------
- /**
- * JDBC 2.0
- *
- * <p>
- * Get the value of a column in the current row as a java.io.Reader.
- * </p>
- *
- * @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.
- *
- * @exception SQLException if a database-access error occurs.
- */
- public boolean isFirst() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "isFirst", args);
- }
- 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 {
- checkRowPos();
- 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);
- }
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public float getFloat(String columnName) throws java.sql.SQLException {
- return getFloat(findColumn(columnName));
- }
- /**
- * Get the value of a column in the current row as a Java int.
- *
- * @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 int getInt(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 Integer.parseInt(val);
- } else {
- // Convert floating point
- return (int) (Double.parseDouble(val));
- }
- } else {
- return 0;
- }
- } catch (NumberFormatException nfe) {
- try {
- // To do: warn on under/overflow?
- return (int) Double.parseDouble(val);
- } catch (NumberFormatException newNfe) {
- ; // ignore, it's not a number
- }
- throw new SQLException("Invalid value for getInt() - '" + val + "'",
- SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public int getInt(String columnName) throws java.sql.SQLException {
- return getInt(findColumn(columnName));
- }
- /**
- * JDBC 2.0
- *
- * <p>
- * Determine if the cursor is on the last row of the result set. Note:
- * Calling isLast() may be expensive since the JDBC driver might need to
- * fetch ahead one row in order to determine whether the current row is
- * the last row in the result set.
- * </p>
- *
- * @return true if on the last row, false otherwise.
- *
- * @exception SQLException if a database-access error occurs.
- */
- public boolean isLast() throws SQLException {
- if (Driver.TRACE) {
- Object[] args = { };
- Debug.methodCall(this, "isLast", args);
- }
- boolean b = rowData.isLast();
- if (Driver.TRACE) {
- Debug.returnValue(this, "relative", new Boolean(b));
- }
- return b;
- }
- /**
- * Get the value of a column in the current row as a Java long.
- *
- * @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 long getLong(int columnIndex) throws java.sql.SQLException {
- checkRowPos();
- String val = null;
- try {
- val = getString(columnIndex);
- if ((val != null) && (val.length() != 0)) {
- if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)) {
- return Long.parseLong(val);
- } else {
- // Convert floating point
- return Double.doubleToLongBits(Double.parseDouble(val));
- }
- } else {
- return 0;
- }
- } catch (NumberFormatException nfe) {
- try {
- // To do: warn on under/overflow?
- return (long) Double.parseDouble(val);
- } catch (NumberFormatException newNfe) {
- ; // ignore, it's not a number
- }
- throw new SQLException("Invalid value for getLong() - '" + val
- + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- }
- /**
- * DOCUMENT ME!
- *
- * @param columnName DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- *
- * @throws java.sql.SQLException DOCUMENT ME!
- */
- public long getLong(String columnName) throws java.sql.SQLException {
- return getLong(findColumn(columnName));
- }
- /**
- * 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 com.mysql.jdbc.ResultSetMetaData(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>
- *
- * <p>
- * This method may also be used to read database specific abstract data
- * types.
- * </p>
- *
- * @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
- * @throws SQLException DOCUMENT ME!
- */
- public Object getObject(int columnIndex) throws java.sql.SQLException {
- checkRowPos();
- if (Driver.TRACE) {
- Object[] args = { new Integer(columnIndex) };
- Debug.methodCall(this, "getObject", args);
- }
- try {
- if (thisRow[columnIndex - 1] == null) {
- 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);
- }
- wasNullFlag = false;
- Field field;
- field = fields[columnIndex - 1];
- switch (field.getSQLType()) {
- case Types.BIT:
- return new Boolean(getBoolean(columnIndex));
- case Types.TINYINT:
- return new Integer(getInt(columnIndex));
- case Types.SMALLINT:
- return new Integer(getInt(columnIndex));
- case Types.INTEGER:
- if (field.isUnsigned()) {
- return new Long(getLong(columnIndex));
- } else {
- return new Integer(getInt(columnIndex));
- }
- case Types.BIGINT:
- if (field.isUnsigned()) {
- return getBigDecimal(columnIndex);
- } else {
- return new Long(getLong(columnIndex));
- }
- case Types.DECIMAL:
- case Types.NUMERIC:
- String stringVal = getString(columnIndex);
- BigDecimal val;
- if (stringVal != null) {
- if (stringVal.length() == 0) {
- val = new BigDecimal(0);
- return val;
- }
- try {
- val = new BigDecimal(stringVal);
- } catch (NumberFormatException ex) {
- throw new java.sql.SQLException(
- "Bad format for BigDecimal '" + stringVal
- + "' in column " + columnIndex + "("
- + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
- }
- return val;
- } else {
- return null;
- }
- case Types.REAL:
- return new Float(getFloat(columnIndex));
- case Types.FLOAT:
- case Types.DOUBLE:
- return new Double(getDouble(columnIndex));
- case Types.CHAR:
- case Types.VARCHAR:
- case Types.LONGVARCHAR:
- return getString(columnIndex);
- case Types.BINARY:
- case Types.VARBINARY:
- case Types.LONGVARBINARY:
- if (!field.isBlob()) {
- return getString(columnIndex);
- } else if (!field.isBinary()) {
- return getString(columnIndex);
- } else {
- byte[] data = getBytes(columnIndex);
- Object obj = data;
- if ((data != null) && (data.length >= 2)) {
- if ((data[0] == -84) && (data[1] == -19)) {
- // Serialized object?
- try {
- ByteArrayInputStream bytesIn = new ByteArrayInputStream(data);
- ObjectInputStream objIn = new ObjectInputStream(bytesIn);
- obj = objIn.readObject();
- objIn.close();
- bytesIn.close();
- } catch (ClassNotFoundException cnfe) {
- throw new SQLException("Class not found: "
- + cnfe.toString()
- + " while reading serialized object");
- } catch (IOException ex) {
- obj = data; // not serialized?
- }
- }
- }
- return obj;
- }
- case Types.DATE:
- return getDate(columnIndex);
- case Types.TIME:
- return getTime(columnIndex);
- case Types.TIMESTAMP:
- return getTimestamp(columnIndex);
- default:
- return getString(columnIndex);
- }
- }
- /**
- * 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>
- *
- * <p>
- * This method may also be used to read database specific abstract data
- * types.
- * </p>
- *
- * @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));
- }
- /**
- * JDBC 2.0 Returns the value of column i as a Java object. Use the map to
- * determine the class from which to construct data of SQL structured and
- * distinct types.
- *
- * @param i the first column is 1, the second is 2, ...
- * @param map the mapping from SQL type names to Java classes
- *
- * @return an object representing the SQL value
- *
- * @throws SQLException because this is not implemented
- */
- public Object getObject(int i, java.util.Map map) throws SQLException {
- return getObject(i);
- }
- /**
- * JDBC 2.0 Returns the value of column i as a Java object. Use the map to
- * determine the class from which to construct data of SQL structured and
- * distinct types.
- *
- * @param colName the column name
- * @param map the mapping from SQL type names to Java classes
- *
- * @return an object representing the SQL value
- *
- * @throws SQLException as this is not implemented
- */
- public Object getObject(String colName, java.util.Map map)
- throws SQLException {
- return getObject(findColumn(colName), map);
- }
- /**
- * JDBC 2.0 Get a REF(<structured-type>) column.
- *
- * @param i the first column is 1, the second is 2, ...
- *
- * @return an object representing data of an SQL REF type
- *
- * @throws SQLException as this is not implemented
- * @throws NotImplemented DOCUMENT ME!
- */
- public java.sql.Ref getRef(int i) throws SQLException {
- throw new NotImplemented();
- }
- /**
- * JDBC 2.0 Get a REF(<structured-type>) column.
- *
- * @param colName the column name
- *
- * @return an object representing data of an SQL REF type
- *
- * @throws SQLException as this method is not implemented.
- * @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);
- }
- 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 {
- checkRowPos();
- 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));
- }