net.sourceforge.jtds.jdbc

Class JtdsResultSet

Implemented Interfaces:
ResultSet
Known Direct Subclasses:
CachedResultSet, MSCursorResultSet

public class JtdsResultSet
extends java.lang.Object
implements ResultSet

jTDS Implementation of the java.sql.ResultSet interface supporting forward read only result sets.

Implementation notes:

  1. This class is also the base for more sophisticated result sets and incorporates the update methods required by them.
  2. The class supports the BLOB/CLOB objects added by Brian.
Version:
$Id: JtdsResultSet.java,v 1.46 2005/09/26 18:21:09 ddkilzer Exp $
Author:
Mike Hutchinson

Field Summary

(package private) static int
CLOSE_CURSORS_AT_COMMIT
(package private) static int
HOLD_CURSORS_OVER_COMMIT
protected static int
INITIAL_ROW_COUNT
Initial size for row array.
protected static int
POS_AFTER_LAST
protected static int
POS_BEFORE_FIRST
protected boolean
cancelled
True if the query has been cancelled by another thread.
protected boolean
closed
True if this result set is closed.
protected int
columnCount
Number of visible columns in row.
private HashMap
columnMap
Cache to optimize findColumn(String) lookups
protected ColInfo[]
columns
The array of column descriptors.
protected int
concurrency
The result set concurrency.
protected Object[]
currentRow
The current result set row.
protected String
cursorName
The cursor name to be used for positioned updates.
protected int
direction
The fetch direction.
private static NumberFormat
f
Used to format numeric values when scale is specified.
protected int
fetchDirection
The fetch direction.
protected int
fetchSize
The fetch size (only applies to cursor ResultSets).
protected int
pos
The current row number.
protected int
resultSetType
The result set type.
protected ArrayList
rowData
Cached row data for forward only result set.
protected int
rowPtr
Index of current row in rowData.
protected int
rowsInResult
The number of rows in the result.
protected JtdsStatement
statement
The parent statement.
protected boolean
wasNull
True if last column retrieved was null.

Constructor Summary

JtdsResultSet(JtdsStatement statement, int resultSetType, int concurrency, ColInfo[] columns)
Construct a simple result set from a statement, metadata or generated keys.

Method Summary

boolean
absolute(int row)
void
afterLast()
void
beforeFirst()
protected void
cacheResultSetRows()
Cache the remaining results to free up connection.
void
cancelRowUpdates()
protected void
checkOpen()
Check that this connection is still open.
protected void
checkScrollable()
Check that this resultset is scrollable.
protected void
checkUpdateable()
Check that this resultset is updateable.
void
clearWarnings()
void
close()
protected ColInfo[]
copyInfo(ColInfo[] info)
Copy an existing result set column descriptor array.
protected Object[]
copyRow(Object[] row)
Copy an existing result set row.
void
deleteRow()
int
findColumn(String columnName)
boolean
first()
Array
getArray(String columnName)
Array
getArray(int columnIndex)
InputStream
getAsciiStream(String columnName)
InputStream
getAsciiStream(int columnIndex)
BigDecimal
getBigDecimal(String columnName)
BigDecimal
getBigDecimal(String columnName, int scale)
BigDecimal
getBigDecimal(int columnIndex)
BigDecimal
getBigDecimal(int columnIndex, int scale)
InputStream
getBinaryStream(String columnName)
InputStream
getBinaryStream(int columnIndex)
Blob
getBlob(String columnName)
Blob
getBlob(int columnIndex)
boolean
getBoolean(String columnName)
boolean
getBoolean(int columnIndex)
byte
getByte(String columnName)
byte
getByte(int columnIndex)
byte[]
getBytes(String columnName)
byte[]
getBytes(int columnIndex)
Reader
getCharacterStream(String columnName)
Reader
getCharacterStream(int columnIndex)
Clob
getClob(String columnName)
Clob
getClob(int columnIndex)
protected Object
getColumn(int index)
Get the specified column's data item.
protected static int
getColumnCount(ColInfo[] columns)
Retrieve the column count excluding hidden columns
protected ColInfo[]
getColumns()
Retrieve the column descriptor array.
int
getConcurrency()
private ConnectionJDBC2
getConnection()
Returns the ConnectionJDBC2 object referenced by the statement instance variable.
protected Object[]
getCurrentRow()
Retrieve the current row data.
String
getCursorName()
Date
getDate(String columnName)
Date
getDate(String columnName, Calendar cal)
Date
getDate(int columnIndex)
Date
getDate(int columnIndex, Calendar cal)
double
getDouble(String columnName)
double
getDouble(int columnIndex)
int
getFetchDirection()
int
getFetchSize()
float
getFloat(String columnName)
float
getFloat(int columnIndex)
int
getInt(String columnName)
int
getInt(int columnIndex)
long
getLong(String columnName)
long
getLong(int columnIndex)
ResultSetMetaData
getMetaData()
Object
getObject(String columnName)
Object
getObject(String columnName, Map map)
Object
getObject(int columnIndex)
Object
getObject(int columnIndex, Map map)
Ref
getRef(String columnName)
Ref
getRef(int columnIndex)
int
getRow()
short
getShort(String columnName)
short
getShort(int columnIndex)
Statement
getStatement()
String
getString(String columnName)
String
getString(int columnIndex)
Time
getTime(String columnName)
Time
getTime(String columnName, Calendar cal)
Time
getTime(int columnIndex)
Time
getTime(int columnIndex, Calendar cal)
Timestamp
getTimestamp(String columnName)
Timestamp
getTimestamp(String columnName, Calendar cal)
Timestamp
getTimestamp(int columnIndex)
Timestamp
getTimestamp(int columnIndex, Calendar cal)
int
getType()
URL
getURL(String columnName)
URL
getURL(int columnIndex)
InputStream
getUnicodeStream(String columnName)
InputStream
getUnicodeStream(int columnIndex)
SQLWarning
getWarnings()
void
insertRow()
boolean
isAfterLast()
boolean
isBeforeFirst()
boolean
isFirst()
boolean
isLast()
boolean
last()
void
moveToCurrentRow()
void
moveToInsertRow()
protected Object[]
newRow()
Create a new row containing empty data items.
boolean
next()
protected static void
notImplemented(String method)
Report that user tried to call a method which has not been implemented.
boolean
previous()
void
refreshRow()
boolean
relative(int row)
boolean
rowDeleted()
boolean
rowInserted()
boolean
rowUpdated()
protected void
setColLabel(int colIndex, String name)
Set the specified column's label.
protected void
setColName(int colIndex, String name)
Set the specified column's name.
protected void
setColType(int colIndex, int jdbcType)
Set the specified column's JDBC type.
protected Object
setColValue(int colIndex, int jdbcType, Object value, int length)
Set the specified column's data value.
protected void
setColumnCount(int columnCount)
Set the current row's column count.
void
setFetchDirection(int direction)
void
setFetchSize(int rows)
void
updateArray(String columnName, Array x)
void
updateArray(int columnIndex, Array x)
void
updateAsciiStream(String columnName, InputStream x, int length)
void
updateAsciiStream(int columnIndex, InputStream inputStream, int length)
void
updateBigDecimal(String columnName, BigDecimal x)
void
updateBigDecimal(int columnIndex, BigDecimal x)
void
updateBinaryStream(String columnName, InputStream x, int length)
void
updateBinaryStream(int columnIndex, InputStream inputStream, int length)
void
updateBlob(String columnName, Blob x)
void
updateBlob(int columnIndex, Blob x)
void
updateBoolean(String columnName, boolean x)
void
updateBoolean(int columnIndex, boolean x)
void
updateByte(String columnName, byte x)
void
updateByte(int columnIndex, byte x)
void
updateBytes(String columnName, byte[] x)
void
updateBytes(int columnIndex, byte[] x)
void
updateCharacterStream(String columnName, Reader x, int length)
void
updateCharacterStream(int columnIndex, Reader reader, int length)
void
updateClob(String columnName, Clob x)
void
updateClob(int columnIndex, Clob x)
void
updateDate(String columnName, Date x)
void
updateDate(int columnIndex, Date x)
void
updateDouble(String columnName, double x)
void
updateDouble(int columnIndex, double x)
void
updateFloat(String columnName, float x)
void
updateFloat(int columnIndex, float x)
void
updateInt(String columnName, int x)
void
updateInt(int columnIndex, int x)
void
updateLong(String columnName, long x)
void
updateLong(int columnIndex, long x)
void
updateNull(String columnName)
void
updateNull(int columnIndex)
void
updateObject(String columnName, Object x)
void
updateObject(String columnName, Object x, int scale)
void
updateObject(int columnIndex, Object x)
void
updateObject(int columnIndex, Object x, int scale)
void
updateRef(String columnName, Ref x)
void
updateRef(int columnIndex, Ref x)
void
updateRow()
void
updateShort(String columnName, short x)
void
updateShort(int columnIndex, short x)
void
updateString(String columnName, String x)
void
updateString(int columnIndex, String x)
void
updateTime(String columnName, Time x)
void
updateTime(int columnIndex, Time x)
void
updateTimestamp(String columnName, Timestamp x)
void
updateTimestamp(int columnIndex, Timestamp x)
boolean
wasNull()

Field Details

CLOSE_CURSORS_AT_COMMIT

(package private) static final int CLOSE_CURSORS_AT_COMMIT
Field Value:
2

HOLD_CURSORS_OVER_COMMIT

(package private) static final int HOLD_CURSORS_OVER_COMMIT
Field Value:
1

INITIAL_ROW_COUNT

protected static final int INITIAL_ROW_COUNT
Initial size for row array.
Field Value:
1000

POS_AFTER_LAST

protected static final int POS_AFTER_LAST
Field Value:
-1

POS_BEFORE_FIRST

protected static final int POS_BEFORE_FIRST
Field Value:
0

cancelled

protected boolean cancelled
True if the query has been cancelled by another thread.

closed

protected boolean closed
True if this result set is closed.

columnCount

protected int columnCount
Number of visible columns in row.

columnMap

private HashMap columnMap
Cache to optimize findColumn(String) lookups

columns

protected ColInfo[] columns
The array of column descriptors.

concurrency

protected int concurrency
The result set concurrency.

currentRow

protected Object[] currentRow
The current result set row.

cursorName

protected String cursorName
The cursor name to be used for positioned updates.

direction

protected int direction
The fetch direction.

f

private static NumberFormat f
Used to format numeric values when scale is specified.

fetchDirection

protected int fetchDirection
The fetch direction.

fetchSize

protected int fetchSize
The fetch size (only applies to cursor ResultSets).

pos

protected int pos
The current row number.

resultSetType

protected int resultSetType
The result set type.

rowData

protected ArrayList rowData
Cached row data for forward only result set.

rowPtr

protected int rowPtr
Index of current row in rowData.

rowsInResult

protected int rowsInResult
The number of rows in the result.

statement

protected JtdsStatement statement
The parent statement.

wasNull

protected boolean wasNull
True if last column retrieved was null.

Constructor Details

JtdsResultSet

(package private)  JtdsResultSet(JtdsStatement statement,
                                 int resultSetType,
                                 int concurrency,
                                 ColInfo[] columns)
            throws SQLException
Construct a simple result set from a statement, metadata or generated keys.
Parameters:
statement - The parent statement object or null.
resultSetType - one of FORWARD_ONLY, SCROLL_INSENSITIVE, SCROLL_SENSITIVE.
concurrency - One of CONCUR_READ_ONLY, CONCUR_UPDATE.
columns - The array of column descriptors for the result set row.

Method Details

absolute

public boolean absolute(int row)
            throws SQLException

afterLast

public void afterLast()
            throws SQLException

beforeFirst

public void beforeFirst()
            throws SQLException

cacheResultSetRows

protected void cacheResultSetRows()
            throws SQLException
Cache the remaining results to free up connection.

cancelRowUpdates

public void cancelRowUpdates()
            throws SQLException

checkOpen

protected void checkOpen()
            throws SQLException
Check that this connection is still open.

checkScrollable

protected void checkScrollable()
            throws SQLException
Check that this resultset is scrollable.

checkUpdateable

protected void checkUpdateable()
            throws SQLException
Check that this resultset is updateable.

clearWarnings

public void clearWarnings()
            throws SQLException

close

public void close()
            throws SQLException

copyInfo

protected ColInfo[] copyInfo(ColInfo[] info)
Copy an existing result set column descriptor array.
Parameters:
info - The result set column descriptors to copy.
Returns:
The new descriptors as a ColInfo[].

copyRow

protected Object[] copyRow(Object[] row)
Copy an existing result set row.
Parameters:
row - the result set row to copy
Returns:
the new row as an Object array

deleteRow

public void deleteRow()
            throws SQLException

findColumn

public int findColumn(String columnName)
            throws SQLException

first

public boolean first()
            throws SQLException

getArray

public Array getArray(String columnName)
            throws SQLException

getArray

public Array getArray(int columnIndex)
            throws SQLException

getAsciiStream

public InputStream getAsciiStream(String columnName)
            throws SQLException

getAsciiStream

public InputStream getAsciiStream(int columnIndex)
            throws SQLException

getBigDecimal

public BigDecimal getBigDecimal(String columnName)
            throws SQLException

getBigDecimal

public BigDecimal getBigDecimal(String columnName,
                                int scale)
            throws SQLException

getBigDecimal

public BigDecimal getBigDecimal(int columnIndex)
            throws SQLException

getBigDecimal

public BigDecimal getBigDecimal(int columnIndex,
                                int scale)
            throws SQLException

getBinaryStream

public InputStream getBinaryStream(String columnName)
            throws SQLException

getBinaryStream

public InputStream getBinaryStream(int columnIndex)
            throws SQLException

getBlob

public Blob getBlob(String columnName)
            throws SQLException

getBlob

public Blob getBlob(int columnIndex)
            throws SQLException

getBoolean

public boolean getBoolean(String columnName)
            throws SQLException

getBoolean

public boolean getBoolean(int columnIndex)
            throws SQLException

getByte

public byte getByte(String columnName)
            throws SQLException

getByte

public byte getByte(int columnIndex)
            throws SQLException

getBytes

public byte[] getBytes(String columnName)
            throws SQLException

getBytes

public byte[] getBytes(int columnIndex)
            throws SQLException

getCharacterStream

public Reader getCharacterStream(String columnName)
            throws SQLException

getCharacterStream

public Reader getCharacterStream(int columnIndex)
            throws SQLException

getClob

public Clob getClob(String columnName)
            throws SQLException

getClob

public Clob getClob(int columnIndex)
            throws SQLException

getColumn

protected Object getColumn(int index)
            throws SQLException
Get the specified column's data item.
Parameters:
index - the column index in the row
Returns:
the column value as an Object

getColumnCount

protected static int getColumnCount(ColInfo[] columns)
Retrieve the column count excluding hidden columns
Parameters:
columns - The columns array
Returns:
The new column count as an int.

getColumns

protected ColInfo[] getColumns()
Retrieve the column descriptor array.
Returns:
The column descriptors as a ColInfo[].

getConcurrency

public int getConcurrency()
            throws SQLException

getConnection

private ConnectionJDBC2 getConnection()
            throws SQLException
Returns the ConnectionJDBC2 object referenced by the statement instance variable.
Returns:
ConnectionJDBC2 object.

getCurrentRow

protected Object[] getCurrentRow()
Retrieve the current row data.
Returns:
The current row data as an Object[].

getCursorName

public String getCursorName()
            throws SQLException

getDate

public Date getDate(String columnName)
            throws SQLException

getDate

public Date getDate(String columnName,
                    Calendar cal)
            throws SQLException

getDate

public Date getDate(int columnIndex)
            throws SQLException

getDate

public Date getDate(int columnIndex,
                    Calendar cal)
            throws SQLException

getDouble

public double getDouble(String columnName)
            throws SQLException

getDouble

public double getDouble(int columnIndex)
            throws SQLException

getFetchDirection

public int getFetchDirection()
            throws SQLException

getFetchSize

public int getFetchSize()
            throws SQLException

getFloat

public float getFloat(String columnName)
            throws SQLException

getFloat

public float getFloat(int columnIndex)
            throws SQLException

getInt

public int getInt(String columnName)
            throws SQLException

getInt

public int getInt(int columnIndex)
            throws SQLException

getLong

public long getLong(String columnName)
            throws SQLException

getLong

public long getLong(int columnIndex)
            throws SQLException

getMetaData

public ResultSetMetaData getMetaData()
            throws SQLException

getObject

public Object getObject(String columnName)
            throws SQLException

getObject

public Object getObject(String columnName,
                        Map map)
            throws SQLException

getObject

public Object getObject(int columnIndex)
            throws SQLException

getObject

public Object getObject(int columnIndex,
                        Map map)
            throws SQLException

getRef

public Ref getRef(String columnName)
            throws SQLException

getRef

public Ref getRef(int columnIndex)
            throws SQLException

getRow

public int getRow()
            throws SQLException

getShort

public short getShort(String columnName)
            throws SQLException

getShort

public short getShort(int columnIndex)
            throws SQLException

getStatement

public Statement getStatement()
            throws SQLException

getString

public String getString(String columnName)
            throws SQLException

getString

public String getString(int columnIndex)
            throws SQLException

getTime

public Time getTime(String columnName)
            throws SQLException

getTime

public Time getTime(String columnName,
                    Calendar cal)
            throws SQLException

getTime

public Time getTime(int columnIndex)
            throws SQLException

getTime

public Time getTime(int columnIndex,
                    Calendar cal)
            throws SQLException

getTimestamp

public Timestamp getTimestamp(String columnName)
            throws SQLException

getTimestamp

public Timestamp getTimestamp(String columnName,
                              Calendar cal)
            throws SQLException

getTimestamp

public Timestamp getTimestamp(int columnIndex)
            throws SQLException

getTimestamp

public Timestamp getTimestamp(int columnIndex,
                              Calendar cal)
            throws SQLException

getType

public int getType()
            throws SQLException

getURL

public URL getURL(String columnName)
            throws SQLException

getURL

public URL getURL(int columnIndex)
            throws SQLException

getUnicodeStream

public InputStream getUnicodeStream(String columnName)
            throws SQLException

getUnicodeStream

public InputStream getUnicodeStream(int columnIndex)
            throws SQLException

getWarnings

public SQLWarning getWarnings()
            throws SQLException

insertRow

public void insertRow()
            throws SQLException

isAfterLast

public boolean isAfterLast()
            throws SQLException

isBeforeFirst

public boolean isBeforeFirst()
            throws SQLException

isFirst

public boolean isFirst()
            throws SQLException

isLast

public boolean isLast()
            throws SQLException

last

public boolean last()
            throws SQLException

moveToCurrentRow

public void moveToCurrentRow()
            throws SQLException

moveToInsertRow

public void moveToInsertRow()
            throws SQLException

newRow

protected Object[] newRow()
Create a new row containing empty data items.
Returns:
the new row as an Object array

next

public boolean next()
            throws SQLException

notImplemented

protected static void notImplemented(String method)
            throws SQLException
Report that user tried to call a method which has not been implemented.
Parameters:
method - The method name to report in the error message.

previous

public boolean previous()
            throws SQLException

refreshRow

public void refreshRow()
            throws SQLException

relative

public boolean relative(int row)
            throws SQLException

rowDeleted

public boolean rowDeleted()
            throws SQLException

rowInserted

public boolean rowInserted()
            throws SQLException

rowUpdated

public boolean rowUpdated()
            throws SQLException

setColLabel

protected void setColLabel(int colIndex,
                           String name)
Set the specified column's label.
Parameters:
colIndex - The index of the column in the row.
name - The new label.

setColName

protected void setColName(int colIndex,
                          String name)
Set the specified column's name.
Parameters:
colIndex - The index of the column in the row.
name - The new name.

setColType

protected void setColType(int colIndex,
                          int jdbcType)
Set the specified column's JDBC type.
Parameters:
colIndex - The index of the column in the row.
jdbcType - The new type value.

setColValue

protected Object setColValue(int colIndex,
                             int jdbcType,
                             Object value,
                             int length)
            throws SQLException
Set the specified column's data value.
Parameters:
colIndex - index of the column
value - new column value
length - the length of a stream parameter
Returns:
the value, possibly converted to an internal type

setColumnCount

protected void setColumnCount(int columnCount)
Set the current row's column count.
Parameters:
columnCount - The number of visible columns in the row.

setFetchDirection

public void setFetchDirection(int direction)
            throws SQLException

setFetchSize

public void setFetchSize(int rows)
            throws SQLException

updateArray

public void updateArray(String columnName,
                        Array x)
            throws SQLException

updateArray

public void updateArray(int columnIndex,
                        Array x)
            throws SQLException

updateAsciiStream

public void updateAsciiStream(String columnName,
                              InputStream x,
                              int length)
            throws SQLException

updateAsciiStream

public void updateAsciiStream(int columnIndex,
                              InputStream inputStream,
                              int length)
            throws SQLException

updateBigDecimal

public void updateBigDecimal(String columnName,
                             BigDecimal x)
            throws SQLException

updateBigDecimal

public void updateBigDecimal(int columnIndex,
                             BigDecimal x)
            throws SQLException

updateBinaryStream

public void updateBinaryStream(String columnName,
                               InputStream x,
                               int length)
            throws SQLException

updateBinaryStream

public void updateBinaryStream(int columnIndex,
                               InputStream inputStream,
                               int length)
            throws SQLException

updateBlob

public void updateBlob(String columnName,
                       Blob x)
            throws SQLException

updateBlob

public void updateBlob(int columnIndex,
                       Blob x)
            throws SQLException

updateBoolean

public void updateBoolean(String columnName,
                          boolean x)
            throws SQLException

updateBoolean

public void updateBoolean(int columnIndex,
                          boolean x)
            throws SQLException

updateByte

public void updateByte(String columnName,
                       byte x)
            throws SQLException

updateByte

public void updateByte(int columnIndex,
                       byte x)
            throws SQLException

updateBytes

public void updateBytes(String columnName,
                        byte[] x)
            throws SQLException

updateBytes

public void updateBytes(int columnIndex,
                        byte[] x)
            throws SQLException

updateCharacterStream

public void updateCharacterStream(String columnName,
                                  Reader x,
                                  int length)
            throws SQLException

updateCharacterStream

public void updateCharacterStream(int columnIndex,
                                  Reader reader,
                                  int length)
            throws SQLException

updateClob

public void updateClob(String columnName,
                       Clob x)
            throws SQLException

updateClob

public void updateClob(int columnIndex,
                       Clob x)
            throws SQLException

updateDate

public void updateDate(String columnName,
                       Date x)
            throws SQLException

updateDate

public void updateDate(int columnIndex,
                       Date x)
            throws SQLException

updateDouble

public void updateDouble(String columnName,
                         double x)
            throws SQLException

updateDouble

public void updateDouble(int columnIndex,
                         double x)
            throws SQLException

updateFloat

public void updateFloat(String columnName,
                        float x)
            throws SQLException

updateFloat

public void updateFloat(int columnIndex,
                        float x)
            throws SQLException

updateInt

public void updateInt(String columnName,
                      int x)
            throws SQLException

updateInt

public void updateInt(int columnIndex,
                      int x)
            throws SQLException

updateLong

public void updateLong(String columnName,
                       long x)
            throws SQLException

updateLong

public void updateLong(int columnIndex,
                       long x)
            throws SQLException

updateNull

public void updateNull(String columnName)
            throws SQLException

updateNull

public void updateNull(int columnIndex)
            throws SQLException

updateObject

public void updateObject(String columnName,
                         Object x)
            throws SQLException

updateObject

public void updateObject(String columnName,
                         Object x,
                         int scale)
            throws SQLException

updateObject

public void updateObject(int columnIndex,
                         Object x)
            throws SQLException

updateObject

public void updateObject(int columnIndex,
                         Object x,
                         int scale)
            throws SQLException

updateRef

public void updateRef(String columnName,
                      Ref x)
            throws SQLException

updateRef

public void updateRef(int columnIndex,
                      Ref x)
            throws SQLException

updateRow

public void updateRow()
            throws SQLException

updateShort

public void updateShort(String columnName,
                        short x)
            throws SQLException

updateShort

public void updateShort(int columnIndex,
                        short x)
            throws SQLException

updateString

public void updateString(String columnName,
                         String x)
            throws SQLException

updateString

public void updateString(int columnIndex,
                         String x)
            throws SQLException

updateTime

public void updateTime(String columnName,
                       Time x)
            throws SQLException

updateTime

public void updateTime(int columnIndex,
                       Time x)
            throws SQLException

updateTimestamp

public void updateTimestamp(String columnName,
                            Timestamp x)
            throws SQLException

updateTimestamp

public void updateTimestamp(int columnIndex,
                            Timestamp x)
            throws SQLException

wasNull

public boolean wasNull()
            throws SQLException

Generated on June 12 2008