com.sas.rio
Class MVAStatement

java.lang.Object
  |
  +--com.sas.rio.MVAStatement
Direct Known Subclasses:
MVAPreparedStatement

public class MVAStatement
extends java.lang.Object
implements RIOStatementInterface

A Statement object is used for executing a static SQL statement and obtaining the results produced by it.

Only one ResultSet per Statement can be open at any point in time. Therefore, if the reading of one ResultSet is interleaved with the reading of another, each must have been generated by different Statements. All statement execute methods implicitly close a statment's current ResultSet if an open one exists.

See Also:
Connection.createStatement(), ResultSet

Field Summary
 long bookmarkLength
           
 org.omg.CORBA.IntHolder bookmarkLengthHolder
           
 int direction
           
 com.sas.iom.SAS.IDataSet sasDataSet
           
 com.sas.iom.SAS.IDataSetHolder sasDataSetHolder
           
 com.sas.iom.SAS.ILibref sasLibref
           
 long status
           
 org.omg.CORBA.IntHolder statusHolder
           
 
Constructor Summary
MVAStatement()
          Constructs a MVAStatement object for MVACallableStatement
MVAStatement(MVAConnection connection)
          Constructs an MVAStatement object.
 
Method Summary
 void addBatch(java.lang.String sql)
          JDBC 2.0 Adds a SQL command to the current batch of commmands for the statement.
 void cancel()
          Cancel can be used by one thread to cancel a statement that is being executed by another thread.
 void clearBatch()
          JDBC 2.0 Make the set of commands in the current batch empty.
 void clearWarnings()
          Clears the warnings for this Statement.
 void close()
          In many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.
 void createTable(java.lang.String libref, java.lang.String tableName, Column[] columnObject, java.lang.String options)
          RIO Creates a new table with the name specified in the tableName String.
 void deleteTable(java.lang.String libref, java.lang.String tableName)
          Deletes the table with the name specified in the tableName String.
 void deleteTable(java.lang.String libref, java.lang.String tableName, java.lang.String tableType, java.lang.String alterPassword)
          RIO Deletes the table for the specified tableType with the name specified in the tableName String.
 boolean execute(java.lang.String sql)
          Execute a SQL statement that may return multiple results.
 int[] executeBatch()
          JDBC 2.0 Submit a batch of commands to the database for execution.
 java.sql.ResultSet executeQuery(java.lang.String query)
          Execute a SQL statement that returns a single ResultSet.
 int executeUpdate(java.lang.String sql)
          Executes an SQL INSERT, UPDATE or DELETE statement.
 java.sql.Connection getConnection()
          JDBC 2.0 Return the Connection that produced the Statement.
 int getFetchDirection()
          JDBC 2.0 Gets the result set fetch direction.
 int getFetchSize()
          JDBC 2.0 Gets the fetch size.
 int getMaxFieldSize()
          The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR columns.
 int getMaxRows()
          The maxRows limit is the maximum number of rows that a ResultSet can contain.
 boolean getMoreResults()
          Moves to a Statement's next result.
 int getQueryTimeout()
          Gets the query timeout limit.
 java.sql.ResultSet getResultSet()
          Gets the current result as a ResultSet.
 int getResultSetConcurrency()
          JDBC 2.0 Gets the result set concurrency type.
 int getResultSetType()
          JDBC 2.0 Gets the result set type.
 java.sql.ResultSet getTable(java.lang.String libref, java.lang.String tableName)
          RIO Gets an MVAResultSet object for the given table name.By default all the columns and all rows are selected.
 java.sql.ResultSet getTable(java.lang.String libref, java.lang.String tableName, java.lang.String tableType, java.lang.String[] password, java.lang.String options)
          RIO Gets an MVAResultSet object for the given table name.
 int getUpdateCount()
          Gets the current result as an update count.If the result is a ResultSet or there are no more results, -1 is returned.
 java.sql.SQLWarning getWarnings()
          Gets the warnings for this statement.
 void setCursorName(java.lang.String name)
          Sets the cursor name.
 void setEscapeProcessing(boolean enable)
          If escape scanning is on (the default), the driver will do escape substitution before sending the SQL to the database.
 void setFetchDirection(int direction)
          JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed.
 void setFetchSize(int rows)
          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.
 void setMaxFieldSize(int max)
          The maxFieldSize limit (in bytes) is set to limit the size of data that can be returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR fields.
 void setMaxRows(int max)
          The maxRows limit is set to limit the number of rows that any ResultSet can contain.
 void setQueryTimeout(int seconds)
          Sets the query timeout limit.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

direction

public int direction

bookmarkLength

public long bookmarkLength

status

public long status

bookmarkLengthHolder

public org.omg.CORBA.IntHolder bookmarkLengthHolder

sasDataSet

public com.sas.iom.SAS.IDataSet sasDataSet

sasDataSetHolder

public com.sas.iom.SAS.IDataSetHolder sasDataSetHolder

statusHolder

public org.omg.CORBA.IntHolder statusHolder

sasLibref

public com.sas.iom.SAS.ILibref sasLibref
Constructor Detail

MVAStatement

public MVAStatement()
Constructs a MVAStatement object for MVACallableStatement

MVAStatement

public MVAStatement(MVAConnection connection)
Constructs an MVAStatement object.
Parameters:
connection - the MVAConnection object associated with this object
Method Detail

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String query)
                                throws java.sql.SQLException
Execute a SQL statement that returns a single ResultSet.
Parameters:
query - Typically this is a static SQL SELECT statement.
Returns:
An MVAResultSet object that contains the data produced by the query.
Throws:
java.sql.SQLException - This exception is thrown if an MVAException is detected.

executeUpdate

public int executeUpdate(java.lang.String sql)
                  throws java.sql.SQLException
Executes an SQL INSERT, UPDATE or DELETE statement.
Parameters:
sql - A SQL INSERT, UPDATE or DELETE statement.
Returns:
The row count for INSERT, UPDATE or DELETE.
Throws:
java.sql.SQLException - This exception is thrown if an exception is detected.

close

public void close()
           throws java.sql.SQLException
In many cases, it is desirable to immediately release a Statements's database and JDBC resources instead of waiting for this to happen when it is automatically closed; the close method provides this immediate release.

Note: A Statement is automatically closed when it is garbage collected. When a Statement is closed, its current ResultSet, if one exists, is also closed.

Throws:
java.sql.SQLException - This exception is thrown if an error condition is detected.

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR columns. If the limit is exceeded, the excess data is silently discarded.
Returns:
The current max column size limit. The default limit is 32767.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws java.sql.SQLException
The maxFieldSize limit (in bytes) is set to limit the size of data that can be returned for any column value; it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR fields. If the limit is exceeded, the excess data is silently discarded. For maximum portability use values greater than 256.
Parameters:
max - The new max column size limit. Zero means unlimited.
Throws:
java.sql.SQLException - This exception is thrown if the max field size is less than 0.

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
The maxRows limit is the maximum number of rows that a ResultSet can contain. If the limit is exceeded, the excess rows are silently dropped. There is no default limit.
Returns:
The current max row limit. Zero means unlimited.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

setMaxRows

public void setMaxRows(int max)
                throws java.sql.SQLException
The maxRows limit is set to limit the number of rows that any ResultSet can contain. If the limit is exceeded, the excess rows are silently dropped.
Parameters:
max - The new max rows limit. Zero means unlimited.
Throws:
java.sql.SQLException - This exception is thrown if the max rows is less than 0.

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws java.sql.SQLException
If escape scanning is on (the default), the driver will do escape substitution before sending the SQL to the database. SAS software does not support escape processing.
Parameters:
enable - The value for this parameter must be False.
Throws:
java.sql.SQLException - This exception is thrown if value of enable is True.

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
Gets the query timeout limit. The queryTimeout limit is the number of seconds the driver will wait for a Statement to execute. If the limit is exceeded, a SQLException is thrown.
Returns:
0. Time out is currently not supported. Zero means unlimited.
Throws:
java.sql.SQLException - if a database-access error occurs.

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws java.sql.SQLException
Sets the query timeout limit. The queryTimeout limit is the number of seconds the driver will wait for a Statement to execute. If the limit is exceeded, a SQLException is thrown.
Parameters:
seconds - The value of this parameter must be 0. Timeout is currently not supported.
Throws:
java.sql.SQLException - This exception is thrown if value of seconds is not equal to 0.

cancel

public void cancel()
            throws java.sql.SQLException
Cancel can be used by one thread to cancel a statement that is being executed by another thread.
Throws:
java.sql.SQLException - This exception may be thrown.

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Gets the warnings for this statement.
Returns:
An SQLWarning.
Throws:
java.sql.SQLException - This exception is required by the interface, but it is never thrown.

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Clears the warnings for this Statement.
Throws:
java.sql.SQLException - This exception is required by the interface, but it is never thrown.

setCursorName

public void setCursorName(java.lang.String name)
                   throws java.sql.SQLException
Sets the cursor name. Cursors are not supported by SAS software so the cursor name will be ignored.
Parameters:
name - The new cursor name.
Throws:
java.sql.SQLException - This exception is required by the interface, but it is never thrown.

execute

public boolean execute(java.lang.String sql)
                throws java.sql.SQLException
Execute a SQL statement that may return multiple results. Under some (uncommon) situations a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this, unless you're executing a stored procedure that you know may return multiple results, or unless you're dynamically executing an unknown SQL string. The "execute", "getMoreResults", "getResultSet" and "getUpdateCount" methods let you navigate through multiple results. The "execute" method executes a SQL statement and indicates the form of the first result. You can then use getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).
Parameters:
sql - An SQL statement
Returns:
True if the next result is a ResultSet. False if it is an update count or there are no more results
Throws:
java.sql.SQLException - This exception is thrown if an MvaException is detected.
See Also:
getResultSet(), getUpdateCount(), getMoreResults()

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException
Gets the current result as a ResultSet. It should only be called once per result.
Returns:
The current result as a ResultSet. NULL if the result is an update count or there are no more results.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.
See Also:
execute(java.lang.String)

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
Gets the current result as an update count.If the result is a ResultSet or there are no more results, -1 is returned. It should only be called once per result.
Returns:
The current result as an update count. -1 if it is a ResultSet or there are no more results.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.
See Also:
execute(java.lang.String)

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
Moves to a Statement's next result. It returns true if this result is a ResultSet. getMoreResults also implicitly closes any current ResultSet obtained with getResultSet. There are no more results when (!getMoreResults() && (getUpdateCount() == -1)
Returns:
False. Multiple result sets are not supported.
Throws:
java.sql.SQLException - This exception may be thrown.
See Also:
execute(java.lang.String)

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
JDBC 2.0 Give a hint as to the direction in which the rows in a result set will be processed. The hint applies only to result sets created using this Statement object. The default value is ResultSet.FETCH_FORWARD.
Parameters:
direction - The initial direction for processing rows.
Throws:
java.sql.SQLException - This exception is thrown if the direction is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or ResultSet.FETCH_UNKNOWN.

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
JDBC 2.0 Gets the result set fetch direction.
Returns:
The result set fetch direction. The default is ResultSet.FETCH_FORWARD.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

setFetchSize

public void setFetchSize(int rows)
                  throws java.sql.SQLException
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. The number of rows specified only affects result sets created using this statement. If the value specified is zero, then the hint is ignored. The default value is zero. TODO: should I check to make sure max rows is non-zero, because zero max rows is unlimited.
Parameters:
rows - The number of rows to fetch.
Throws:
java.sql.SQLException - This exception is thrown if the condition 0 <= rows <= this.getMaxRows() is not satisfied.

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
JDBC 2.0 Gets the fetch size.
Returns:
An integer value indicating the number of rows fetched for this result set.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
JDBC 2.0 Gets the result set concurrency type.
Returns:
The result set concurrency type, CONCUR_UPDATABLE or CONCUR_READ_ONLY.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

getResultSetType

public int getResultSetType()
                     throws java.sql.SQLException
JDBC 2.0 Gets the result set type.
Returns:
The result set type, TYPE_SCROLL_INSENSITIVE or TYPE_FORWARD_ONLY. Changes made while the result set is open are not visible.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

addBatch

public void addBatch(java.lang.String sql)
              throws java.sql.SQLException
JDBC 2.0 Adds a SQL command to the current batch of commmands for the statement. This method is optional.
Parameters:
sql - typically this is a static SQL INSERT or UPDATE statement
Throws:
java.sql.SQLException - if a database-access error occurs, or the driver does not support batch statements

clearBatch

public void clearBatch()
                throws java.sql.SQLException
JDBC 2.0 Make the set of commands in the current batch empty. This method is optional.
Throws:
java.sql.SQLException - if a database-access error occurs, or the driver does not support batch statements

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
JDBC 2.0 Submit a batch of commands to the database for execution. This method is optional.
Returns:
an array of update counts containing one element for each command in the batch. The array is ordered according to the order in which commands were inserted into the batch
Throws:
java.sql.SQLException - if a database-access error occurs, or the driver does not support batch statements

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
JDBC 2.0 Return the Connection that produced the Statement.
Returns:
the Connection object.
Throws:
java.sql.SQLException - This exception is required by the interface but it is never thrown.

createTable

public void createTable(java.lang.String libref,
                        java.lang.String tableName,
                        Column[] columnObject,
                        java.lang.String options)
                 throws com.sas.rio.RIOException
RIO Creates a new table with the name specified in the tableName String. The columns to be created and their attributes are passed through the columnObject parameter. Any SAS options to be sent with the create table will be passed through the optionsObject parameter.
Specified by:
createTable in interface RIOStatementInterface
Parameters:
libref - The libref name. Cannot be NULL.
tableName - The name of the table to be created. Table name cannot be NULL.
columnObject - A Column Object array containing column names and attributes. Column object cannot be NULL.
options - A String of applicaaple SAS dataset options. May be NULL.
Throws:
com.sas.rio.RIOException - This exception may be thrown.

getTable

public java.sql.ResultSet getTable(java.lang.String libref,
                                   java.lang.String tableName)
                            throws com.sas.rio.RIOException
RIO Gets an MVAResultSet object for the given table name.By default all the columns and all rows are selected.
Specified by:
getTable in interface RIOStatementInterface
Parameters:
libref - The libref name. Cannot be NULL.
tableName - The name of the table. Table name cannot be NULL. By default, the driver looks for a dataset to open, if one doesn't exist it looks for a view to open. If both exist, it opens a dataset.
Returns:
An MVAResultSet object. All columns and all rows are selected.
Throws:
com.sas.rio.RIOException - This exception may be thrown.

getTable

public java.sql.ResultSet getTable(java.lang.String libref,
                                   java.lang.String tableName,
                                   java.lang.String tableType,
                                   java.lang.String[] password,
                                   java.lang.String options)
                            throws com.sas.rio.RIOException
RIO Gets an MVAResultSet object for the given table name.
Specified by:
getTable in interface RIOStatementInterface
Parameters:
libref - The libref name. Cannot be NULL.
tableName - The name of the table to be opened.
tableType - The type of the table to be opened.It could be "DATA" or "VIEW". If NULL, the driver looks for a dataset to open, if one doesn't exist it looks for a view to open. If both exist, it opens a dataset. This parameter is currently being ignored and defaulted to NULL.
password - A String array of 3 elements specifying READ, WRITE and ALTER passwords if any. This parameter can be NULL. The first element is the READ password, the second the WRITE password and the third the ALTER password.
options - A String whose contents can be any SAS dataset options appropriate to the underlying engine and library. This includes the WHERE clause. options can be NULL.
Returns:
An MVAResultSet object. The ResultSet could be a subset of the actual set of columns and rows.
Throws:
com.sas.rio.RIOException - This exception may be thrown.

deleteTable

public void deleteTable(java.lang.String libref,
                        java.lang.String tableName)
                 throws com.sas.rio.RIOException
Deletes the table with the name specified in the tableName String.
Specified by:
deleteTable in interface RIOStatementInterface
Parameters:
libref - The libref name. Cannot be NULL.
tableName - The name of the table to be deleted. By default, the tableName dataset will be deleted.
Throws:
com.sas.rio.RIOException - This exception may be thrown.

deleteTable

public void deleteTable(java.lang.String libref,
                        java.lang.String tableName,
                        java.lang.String tableType,
                        java.lang.String alterPassword)
                 throws com.sas.rio.RIOException
RIO Deletes the table for the specified tableType with the name specified in the tableName String.
Specified by:
deleteTable in interface RIOStatementInterface
Parameters:
libref - The libref name. Cannot be NULL.
tableName - The name of the table to be deleted.
tableType - The type of the table. It could be "DATA" or "VIEW" or any table type available in the database. If NULL, the tableName dataset will be deleted.
alterPassword - The alter password.
Throws:
com.sas.rio.RIOException - This exception may be thrown.