home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / ResultSet.java < prev    next >
Text File  |  1997-05-20  |  25KB  |  585 lines

  1. /*
  2.  * @(#)ResultSet.java    1.7 97/02/11
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.sql;
  24.  
  25. import java.math.BigDecimal;
  26.  
  27. /**
  28.  * <P>A ResultSet provides access to a table of data generated by
  29.  * executing a Statement. The table rows are retrieved in
  30.  * sequence. Within a row its column values can be accessed in any
  31.  * order.
  32.  * 
  33.  * <P>A ResultSet maintains a cursor pointing to its current row of
  34.  * data.  Initially the cursor is positioned before the first row.
  35.  * The 'next' method moves the cursor to the next row.
  36.  *
  37.  * <P>The getXXX methods retrieve column values for the current
  38.  * row.  You can retrieve values either using the index number of the
  39.  * column, or by using the name of the column.  In general using the 
  40.  * column index will be more efficient.  Columns are numbered from 1.
  41.  *
  42.  * <P>For maximum portability, ResultSet columns within each row should be
  43.  * read in left-to-right order and each column should be read only once.
  44.  *
  45.  * <P>For the getXXX methods, the JDBC driver attempts to convert the
  46.  * underlying data to the specified Java type and returns a suitable
  47.  * Java value.  See the JDBC specification for allowable mappings
  48.  * from SQL types to Java types with the ResultSet.getXXX methods.
  49.  *
  50.  * <P>Column names used as input to getXXX methods are case
  51.  * insensitive.  When performing a getXXX using a column name, if
  52.  * several columns have the same name, then the value of the first
  53.  * matching column will be returned. The column name option is
  54.  * designed to be used when column names are used in the SQL
  55.  * query. For columns that are NOT explicitly named in the query, it
  56.  * is best to use column numbers. If column names were used there is
  57.  * no way for the programmer to guarantee that they actually refer to
  58.  * the intended columns.
  59.  *
  60.  * <P>A ResultSet is automatically closed by the Statement that
  61.  * generated it when that Statement is closed, re-executed, or is used
  62.  * to retrieve the next result from a sequence of multiple results.
  63.  * 
  64.  * <P>The number, types and properties of a ResultSet's columns are
  65.  * provided by the ResulSetMetaData object returned by the getMetaData
  66.  * method.
  67.  *
  68.  * @see Statement#executeQuery 
  69.  * @see Statement#getResultSet 
  70.  * @see ResultSetMetaData 
  71.  */
  72.  
  73. public interface ResultSet {
  74.  
  75.     /**
  76.      * A ResultSet is initially positioned before its first row; the
  77.      * first call to next makes the first row the current row; the
  78.      * second call makes the second row the current row, etc. 
  79.      *
  80.      * <P>If an input stream from the previous row is open, it is
  81.      * implicitly closed. The ResultSet's warning chain is cleared
  82.      * when a new row is read.
  83.      *
  84.      * @return true if the new current row is valid; false if there
  85.      * are no more rows 
  86.      * @exception SQLException if a database-access error occurs.
  87.      */
  88.     boolean next() throws SQLException;
  89.  
  90.  
  91.     /**
  92.      * In some cases, it is desirable to immediately release a
  93.      * ResultSet's database and JDBC resources instead of waiting for
  94.      * this to happen when it is automatically closed; the close
  95.      * method provides this immediate release.
  96.      *
  97.      * <P><B>Note:</B> A ResultSet is automatically closed by the
  98.      * Statement that generated it when that Statement is closed,
  99.      * re-executed, or is used to retrieve the next result from a
  100.      * sequence of multiple results. A ResultSet is also automatically
  101.      * closed when it is garbage collected.  
  102.      *
  103.      * @exception SQLException if a database-access error occurs.
  104.      */
  105.     void close() throws SQLException;
  106.  
  107.     /**
  108.      * A column may have the value of SQL NULL; wasNull reports whether
  109.      * the last column read had this special value.
  110.      * Note that you must first call getXXX on a column to try to read
  111.      * its value and then call wasNull() to find if the value was
  112.      * the SQL NULL.
  113.      *
  114.      * @return true if last column read was SQL NULL
  115.      * @exception SQLException if a database-access error occurs.
  116.      */
  117.     boolean wasNull() throws SQLException;
  118.     
  119.     //======================================================================
  120.     // Methods for accessing results by column index
  121.     //======================================================================
  122.  
  123.     /**
  124.      * Get the value of a column in the current row as a Java String.
  125.      *
  126.      * @param columnIndex the first column is 1, the second is 2, ...
  127.      * @return the column value; if the value is SQL NULL, the result is null
  128.      * @exception SQLException if a database-access error occurs.
  129.      */
  130.     String getString(int columnIndex) throws SQLException;
  131.  
  132.     /**
  133.      * Get the value of a column in the current row as a Java boolean.
  134.      *
  135.      * @param columnIndex the first column is 1, the second is 2, ...
  136.      * @return the column value; if the value is SQL NULL, the result is false
  137.      * @exception SQLException if a database-access error occurs.
  138.      */
  139.     boolean getBoolean(int columnIndex) throws SQLException;
  140.  
  141.     /**
  142.      * Get the value of a column in the current row as a Java byte.
  143.      *
  144.      * @param columnIndex the first column is 1, the second is 2, ...
  145.      * @return the column value; if the value is SQL NULL, the result is 0
  146.      * @exception SQLException if a database-access error occurs.
  147.      */
  148.     byte getByte(int columnIndex) throws SQLException;
  149.  
  150.     /**
  151.      * Get the value of a column in the current row as a Java short.
  152.      *
  153.      * @param columnIndex the first column is 1, the second is 2, ...
  154.      * @return the column value; if the value is SQL NULL, the result is 0
  155.      * @exception SQLException if a database-access error occurs.
  156.      */
  157.     short getShort(int columnIndex) throws SQLException;
  158.  
  159.     /**
  160.      * Get the value of a column in the current row as a Java int.
  161.      *
  162.      * @param columnIndex the first column is 1, the second is 2, ...
  163.      * @return the column value; if the value is SQL NULL, the result is 0
  164.      * @exception SQLException if a database-access error occurs.
  165.      */
  166.     int getInt(int columnIndex) throws SQLException;
  167.  
  168.     /**
  169.      * Get the value of a column in the current row as a Java long.
  170.      *
  171.      * @param columnIndex the first column is 1, the second is 2, ...
  172.      * @return the column value; if the value is SQL NULL, the result is 0
  173.      * @exception SQLException if a database-access error occurs.
  174.      */
  175.     long getLong(int columnIndex) throws SQLException;
  176.  
  177.     /**
  178.      * Get the value of a column in the current row as a Java float.
  179.      *
  180.      * @param columnIndex the first column is 1, the second is 2, ...
  181.      * @return the column value; if the value is SQL NULL, the result is 0
  182.      * @exception SQLException if a database-access error occurs.
  183.      */
  184.     float getFloat(int columnIndex) throws SQLException;
  185.  
  186.     /**
  187.      * Get the value of a column in the current row as a Java double.
  188.      *
  189.      * @param columnIndex the first column is 1, the second is 2, ...
  190.      * @return the column value; if the value is SQL NULL, the result is 0
  191.      * @exception SQLException if a database-access error occurs.
  192.      */
  193.     double getDouble(int columnIndex) throws SQLException;
  194.  
  195.     /**
  196.      * Get the value of a column in the current row as a java.lang.BigDecimal object.
  197.      *
  198.      * @param columnIndex the first column is 1, the second is 2, ...
  199.      * @param scale the number of digits to the right of the decimal
  200.      * @return the column value; if the value is SQL NULL, the result is null
  201.      * @exception SQLException if a database-access error occurs.
  202.      */
  203.     BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException;
  204.  
  205.     /**
  206.      * Get the value of a column in the current row as a Java byte array.
  207.      * The bytes represent the raw values returned by the driver.
  208.      *
  209.      * @param columnIndex the first column is 1, the second is 2, ...
  210.      * @return the column value; if the value is SQL NULL, the result is null
  211.      * @exception SQLException if a database-access error occurs.
  212.      */
  213.     byte[] getBytes(int columnIndex) throws SQLException;
  214.  
  215.     /**
  216.      * Get the value of a column in the current row as a java.sql.Date object.
  217.      *
  218.      * @param columnIndex the first column is 1, the second is 2, ...
  219.      * @return the column value; if the value is SQL NULL, the result is null
  220.      * @exception SQLException if a database-access error occurs.
  221.      */
  222.     java.sql.Date getDate(int columnIndex) throws SQLException;
  223.  
  224.     /**
  225.      * Get the value of a column in the current row as a java.sql.Time object.
  226.      *
  227.      * @param columnIndex the first column is 1, the second is 2, ...
  228.      * @return the column value; if the value is SQL NULL, the result is null
  229.      * @exception SQLException if a database-access error occurs.
  230.      */
  231.     java.sql.Time getTime(int columnIndex) throws SQLException;
  232.  
  233.     /**
  234.      * Get the value of a column in the current row as a java.sql.Timestamp object.
  235.      *
  236.      * @param columnIndex the first column is 1, the second is 2, ...
  237.      * @return the column value; if the value is SQL NULL, the result is null
  238.      * @exception SQLException if a database-access error occurs.
  239.      */
  240.     java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException;
  241.  
  242.     /**
  243.      * A column value can be retrieved as a stream of ASCII characters 
  244.      * and then read in chunks from the stream.  This method is particularly
  245.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  246.      * do any necessary conversion from the database format into ASCII.
  247.      *
  248.      * <P><B>Note:</B> All the data in the returned stream must be
  249.      * read prior to getting the value of any other column. The next
  250.      * call to a get method implicitly closes the stream. . Also, a
  251.      * stream may return 0 for available() whether there is data
  252.      * available or not.
  253.      *
  254.      * @param columnIndex the first column is 1, the second is 2, ...
  255.      * @return a Java input stream that delivers the database column value
  256.      * as a stream of one byte ASCII characters.  If the value is SQL NULL
  257.      * then the result is null.  
  258.      * @exception SQLException if a database-access error occurs.
  259.      */
  260.     java.io.InputStream getAsciiStream(int columnIndex) throws SQLException;
  261.  
  262.     /**
  263.      * A column value can be retrieved as a stream of Unicode characters 
  264.      * and then read in chunks from the stream.  This method is particularly
  265.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  266.      * do any necessary conversion from the database format into Unicode.
  267.      *
  268.      * <P><B>Note:</B> All the data in the returned stream must be
  269.      * read prior to getting the value of any other column. The next
  270.      * call to a get method implicitly closes the stream. . Also, a
  271.      * stream may return 0 for available() whether there is data
  272.      * available or not.
  273.      *
  274.      * @param columnIndex the first column is 1, the second is 2, ...
  275.      * @return a Java input stream that delivers the database column value
  276.      * as a stream of two byte Unicode characters.  If the value is SQL NULL
  277.      * then the result is null.  
  278.      * @exception SQLException if a database-access error occurs.
  279.      */
  280.     java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException;
  281.  
  282.     /**
  283.      * A column value can be retrieved as a stream of uninterpreted bytes 
  284.      * and then read in chunks from the stream.  This method is particularly
  285.      * suitable for retrieving large LONGVARBINARY values.
  286.      *
  287.      * <P><B>Note:</B> All the data in the returned stream must be
  288.      * read prior to getting the value of any other column. The next
  289.      * call to a get method implicitly closes the stream. Also, a
  290.      * stream may return 0 for available() whether there is data
  291.      * available or not.
  292.      *
  293.      * @param columnIndex the first column is 1, the second is 2, ...
  294.      * @return a Java input stream that delivers the database column value
  295.      * as a stream of uninterpreted bytes.  If the value is SQL NULL
  296.      * then the result is null.  
  297.      * @exception SQLException if a database-access error occurs.
  298.      */
  299.     java.io.InputStream getBinaryStream(int columnIndex)
  300.         throws SQLException;
  301.  
  302.  
  303.     //======================================================================
  304.     // Methods for accessing results by column name
  305.     //======================================================================
  306.  
  307.     /**
  308.      * Get the value of a column in the current row as a Java String.
  309.      *
  310.      * @param columnName is the SQL name of the column
  311.      * @return the column value; if the value is SQL NULL, the result is null
  312.      * @exception SQLException if a database-access error occurs.
  313.      */
  314.     String getString(String columnName) throws SQLException;
  315.  
  316.     /**
  317.      * Get the value of a column in the current row as a Java boolean.
  318.      *
  319.      * @param columnName is the SQL name of the column
  320.      * @return the column value; if the value is SQL NULL, the result is false
  321.      * @exception SQLException if a database-access error occurs.
  322.      */
  323.     boolean getBoolean(String columnName) throws SQLException;
  324.  
  325.     /**
  326.      * Get the value of a column in the current row as a Java byte.
  327.      *
  328.      * @param columnName is the SQL name of the column
  329.      * @return the column value; if the value is SQL NULL, the result is 0
  330.      * @exception SQLException if a database-access error occurs.
  331.      */
  332.     byte getByte(String columnName) throws SQLException;
  333.  
  334.     /**
  335.      * Get the value of a column in the current row as a Java short.
  336.      *
  337.      * @param columnName is the SQL name of the column
  338.      * @return the column value; if the value is SQL NULL, the result is 0
  339.      * @exception SQLException if a database-access error occurs.
  340.      */
  341.     short getShort(String columnName) throws SQLException;
  342.  
  343.     /**
  344.      * Get the value of a column in the current row as a Java int.
  345.      *
  346.      * @param columnName is the SQL name of the column
  347.      * @return the column value; if the value is SQL NULL, the result is 0
  348.      * @exception SQLException if a database-access error occurs.
  349.      */
  350.     int getInt(String columnName) throws SQLException;
  351.  
  352.     /**
  353.      * Get the value of a column in the current row as a Java long.
  354.      *
  355.      * @param columnName is the SQL name of the column
  356.      * @return the column value; if the value is SQL NULL, the result is 0
  357.      * @exception SQLException if a database-access error occurs.
  358.      */
  359.     long getLong(String columnName) throws SQLException;
  360.  
  361.     /**
  362.      * Get the value of a column in the current row as a Java float.
  363.      *
  364.      * @param columnName is the SQL name of the column
  365.      * @return the column value; if the value is SQL NULL, the result is 0
  366.      * @exception SQLException if a database-access error occurs.
  367.      */
  368.     float getFloat(String columnName) throws SQLException;
  369.  
  370.     /**
  371.      * Get the value of a column in the current row as a Java double.
  372.      *
  373.      * @param columnName is the SQL name of the column
  374.      * @return the column value; if the value is SQL NULL, the result is 0
  375.      * @exception SQLException if a database-access error occurs.
  376.      */
  377.     double getDouble(String columnName) throws SQLException;
  378.  
  379.     /**
  380.      * Get the value of a column in the current row as a java.lang.BigDecimal object.
  381.      *
  382.      * @param columnName is the SQL name of the column
  383.      * @param scale the number of digits to the right of the decimal
  384.      * @return the column value; if the value is SQL NULL, the result is null
  385.      * @exception SQLException if a database-access error occurs.
  386.      */
  387.     BigDecimal getBigDecimal(String columnName, int scale) throws SQLException;
  388.  
  389.     /**
  390.      * Get the value of a column in the current row as a Java byte array.
  391.      * The bytes represent the raw values returned by the driver.
  392.      *
  393.      * @param columnName is the SQL name of the column
  394.      * @return the column value; if the value is SQL NULL, the result is null
  395.      * @exception SQLException if a database-access error occurs.
  396.      */
  397.     byte[] getBytes(String columnName) throws SQLException;
  398.  
  399.     /**
  400.      * Get the value of a column in the current row as a java.sql.Date object.
  401.      *
  402.      * @param columnName is the SQL name of the column
  403.      * @return the column value; if the value is SQL NULL, the result is null
  404.      * @exception SQLException if a database-access error occurs.
  405.      */
  406.     java.sql.Date getDate(String columnName) throws SQLException;
  407.  
  408.     /**
  409.      * Get the value of a column in the current row as a java.sql.Time object.
  410.      *
  411.      * @param columnName is the SQL name of the column
  412.      * @return the column value; if the value is SQL NULL, the result is null
  413.      * @exception SQLException if a database-access error occurs.
  414.      */
  415.     java.sql.Time getTime(String columnName) throws SQLException;
  416.  
  417.     /**
  418.      * Get the value of a column in the current row as a java.sql.Timestamp object.
  419.      *
  420.      * @param columnName is the SQL name of the column
  421.      * @return the column value; if the value is SQL NULL, the result is null
  422.      * @exception SQLException if a database-access error occurs.
  423.      */
  424.     java.sql.Timestamp getTimestamp(String columnName) throws SQLException;
  425.  
  426.     /**
  427.      * A column value can be retrieved as a stream of ASCII characters 
  428.      * and then read in chunks from the stream.  This method is particularly
  429.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  430.      * do any necessary conversion from the database format into ASCII.
  431.      *
  432.      * <P><B>Note:</B> All the data in the returned stream must
  433.      * be read prior to getting the value of any other column. The
  434.      * next call to a get method implicitly closes the stream.
  435.      *
  436.      * @param columnName is the SQL name of the column
  437.      * @return a Java input stream that delivers the database column value
  438.      * as a stream of one byte ASCII characters.  If the value is SQL NULL
  439.      * then the result is null.
  440.      * @exception SQLException if a database-access error occurs.
  441.      */
  442.     java.io.InputStream getAsciiStream(String columnName) throws SQLException;
  443.  
  444.     /**
  445.      * A column value can be retrieved as a stream of Unicode characters 
  446.      * and then read in chunks from the stream.  This method is particularly
  447.      * suitable for retrieving large LONGVARCHAR values.  The JDBC driver will
  448.      * do any necessary conversion from the database format into Unicode.
  449.      *
  450.      * <P><B>Note:</B> All the data in the returned stream must
  451.      * be read prior to getting the value of any other column. The
  452.      * next call to a get method implicitly closes the stream.
  453.      *
  454.      * @param columnName is the SQL name of the column
  455.      * @return a Java input stream that delivers the database column value
  456.      * as a stream of two byte Unicode characters.  If the value is SQL NULL
  457.      * then the result is null.
  458.      * @exception SQLException if a database-access error occurs.
  459.      */
  460.     java.io.InputStream getUnicodeStream(String columnName) throws SQLException;
  461.  
  462.     /**
  463.      * A column value can be retrieved as a stream of uninterpreted bytes 
  464.      * and then read in chunks from the stream.  This method is particularly
  465.      * suitable for retrieving large LONGVARBINARY values.
  466.      *
  467.      * <P><B>Note:</B> All the data in the returned stream must
  468.      * be read prior to getting the value of any other column. The
  469.      * next call to a get method implicitly closes the stream.
  470.      *
  471.      * @param columnName is the SQL name of the column
  472.      * @return a Java input stream that delivers the database column value
  473.      * as a stream of uninterpreted bytes.  If the value is SQL NULL
  474.      * then the result is null.
  475.      * @exception SQLException if a database-access error occurs.
  476.      */
  477.     java.io.InputStream getBinaryStream(String columnName)
  478.         throws SQLException;
  479.  
  480.  
  481.     //=====================================================================
  482.     // Advanced features:
  483.     //=====================================================================
  484.  
  485.     /**
  486.      * <p>The first warning reported by calls on this ResultSet is
  487.      * returned. Subsequent ResultSet warnings will be chained to this
  488.      * SQLWarning.
  489.      *
  490.      * <P>The warning chain is automatically cleared each time a new
  491.      * row is read.
  492.      *
  493.      * <P><B>Note:</B> This warning chain only covers warnings caused
  494.      * by ResultSet methods.  Any warning caused by statement methods
  495.      * (such as reading OUT parameters) will be chained on the
  496.      * Statement object. 
  497.      *
  498.      * @return the first SQLWarning or null 
  499.      * @exception SQLException if a database-access error occurs.
  500.      */
  501.     SQLWarning getWarnings() throws SQLException;
  502.  
  503.     /**
  504.      * After this call getWarnings returns null until a new warning is
  505.      * reported for this ResultSet.  
  506.      *
  507.      * @exception SQLException if a database-access error occurs.
  508.      */
  509.     void clearWarnings() throws SQLException;
  510.  
  511.     /**
  512.      * Get the name of the SQL cursor used by this ResultSet.
  513.      *
  514.      * <P>In SQL, a result table is retrieved through a cursor that is
  515.      * named. The current row of a result can be updated or deleted
  516.      * using a positioned update/delete statement that references the
  517.      * cursor name. 
  518.      * 
  519.      * <P>JDBC supports this SQL feature by providing the name of the
  520.      * SQL cursor used by a ResultSet. The current row of a ResultSet
  521.      * is also the current row of this SQL cursor.
  522.      *
  523.      * <P><B>Note:</B> If positioned update is not supported a
  524.      * SQLException is thrown
  525.      *
  526.      * @return the ResultSet's SQL cursor name
  527.      * @exception SQLException if a database-access error occurs.
  528.      */
  529.     String getCursorName() throws SQLException;
  530.  
  531.     /**
  532.      * The number, types and properties of a ResultSet's columns
  533.      * are provided by the getMetaData method.
  534.      *
  535.      * @return the description of a ResultSet's columns
  536.      * @exception SQLException if a database-access error occurs.
  537.      */
  538.     ResultSetMetaData getMetaData() throws SQLException;
  539.  
  540.     /**
  541.      * <p>Get the value of a column in the current row as a Java object.
  542.      *
  543.      * <p>This method will return the value of the given column as a
  544.      * Java object.  The type of the Java object will be the default
  545.      * Java Object type corresponding to the column's SQL type,
  546.      * following the mapping specified in the JDBC spec.
  547.      *
  548.      * <p>This method may also be used to read datatabase specific abstract
  549.      * data types.
  550.      *
  551.      * @param columnIndex the first column is 1, the second is 2, ...
  552.      * @return A java.lang.Object holding the column value.  
  553.      * @exception SQLException if a database-access error occurs.
  554.      */
  555.     Object getObject(int columnIndex) throws SQLException;
  556.  
  557.     /**
  558.      * <p>Get the value of a column in the current row as a Java object.
  559.      *
  560.      * <p>This method will return the value of the given column as a
  561.      * Java object.  The type of the Java object will be the default
  562.      * Java Object type corresponding to the column's SQL type,
  563.      * following the mapping specified in the JDBC spec.
  564.      *
  565.      * <p>This method may also be used to read datatabase specific abstract
  566.      * data types.
  567.      *
  568.      * @param columnName is the SQL name of the column
  569.      * @return A java.lang.Object holding the column value.  
  570.      * @exception SQLException if a database-access error occurs.
  571.      */
  572.     Object getObject(String columnName) throws SQLException;
  573.  
  574.     //----------------------------------------------------------------
  575.  
  576.     /**
  577.      * Map a Resultset column name to a ResultSet column index.
  578.      *
  579.      * @param columnName the name of the column
  580.      * @return the column index
  581.      * @exception SQLException if a database-access error occurs.
  582.      */
  583.     int findColumn(String columnName) throws SQLException;
  584. }
  585.