home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / Main.bin / PreparedStatement.java < prev    next >
Text File  |  1998-09-22  |  14KB  |  340 lines

  1. /*
  2.  * @(#)PreparedStatement.java    1.9 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.sql;
  16.  
  17. import java.math.BigDecimal;
  18.  
  19. /**
  20.  * <P>A SQL statement is pre-compiled and stored in a
  21.  * PreparedStatement object. This object can then be used to
  22.  * efficiently execute this statement multiple times. 
  23.  *
  24.  * <P><B>Note:</B> The setXXX methods for setting IN parameter values
  25.  * must specify types that are compatible with the defined SQL type of
  26.  * the input parameter. For instance, if the IN parameter has SQL type
  27.  * Integer then setInt should be used.
  28.  *
  29.  * <p>If arbitrary parameter type conversions are required then the
  30.  * setObject method should be used with a target SQL type.
  31.  *
  32.  * @see Connection#prepareStatement
  33.  * @see ResultSet 
  34.  */
  35.  
  36. public interface PreparedStatement extends Statement {
  37.  
  38.     /**
  39.      * A prepared SQL query is executed and its ResultSet is returned.
  40.      *
  41.      * @return a ResultSet that contains the data produced by the
  42.      * query; never null
  43.      * @exception SQLException if a database-access error occurs.
  44.      */
  45.     ResultSet executeQuery() throws SQLException;
  46.  
  47.     /**
  48.      * Execute a SQL INSERT, UPDATE or DELETE statement. In addition,
  49.      * SQL statements that return nothing such as SQL DDL statements
  50.      * can be executed.
  51.      *
  52.      * @return either the row count for INSERT, UPDATE or DELETE; or 0
  53.      * for SQL statements that return nothing
  54.      * @exception SQLException if a database-access error occurs.
  55.      */
  56.     int executeUpdate() throws SQLException;
  57.  
  58.     /**
  59.      * Set a parameter to SQL NULL.
  60.      *
  61.      * <P><B>Note:</B> You must specify the parameter's SQL type.
  62.      *
  63.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  64.      * @param sqlType SQL type code defined by java.sql.Types
  65.      * @exception SQLException if a database-access error occurs.
  66.      */
  67.     void setNull(int parameterIndex, int sqlType) throws SQLException;
  68.  
  69.     /**
  70.      * Set a parameter to a Java boolean value.  The driver converts this
  71.      * to a SQL BIT value when it sends it to the database.
  72.      *
  73.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  74.      * @param x the parameter value
  75.      * @exception SQLException if a database-access error occurs.
  76.      */
  77.     void setBoolean(int parameterIndex, boolean x) throws SQLException;
  78.  
  79.     /**
  80.      * Set a parameter to a Java byte value.  The driver converts this
  81.      * to a SQL TINYINT value when it sends it to the database.
  82.      *
  83.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  84.      * @param x the parameter value
  85.      * @exception SQLException if a database-access error occurs.
  86.      */
  87.     void setByte(int parameterIndex, byte x) throws SQLException;
  88.  
  89.     /**
  90.      * Set a parameter to a Java short value.  The driver converts this
  91.      * to a SQL SMALLINT value when it sends it to the database.
  92.      *
  93.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  94.      * @param x the parameter value
  95.      * @exception SQLException if a database-access error occurs.
  96.      */
  97.     void setShort(int parameterIndex, short x) throws SQLException;
  98.  
  99.     /**
  100.      * Set a parameter to a Java int value.  The driver converts this
  101.      * to a SQL INTEGER value when it sends it to the database.
  102.      *
  103.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  104.      * @param x the parameter value
  105.      * @exception SQLException if a database-access error occurs.
  106.      */
  107.     void setInt(int parameterIndex, int x) throws SQLException;
  108.  
  109.     /**
  110.      * Set a parameter to a Java long value.  The driver converts this
  111.      * to a SQL BIGINT value when it sends it to the database.
  112.      *
  113.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  114.      * @param x the parameter value
  115.      * @exception SQLException if a database-access error occurs.
  116.      */
  117.     void setLong(int parameterIndex, long x) throws SQLException;
  118.  
  119.     /**
  120.      * Set a parameter to a Java float value.  The driver converts this
  121.      * to a SQL FLOAT value when it sends it to the database.
  122.      *
  123.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  124.      * @param x the parameter value
  125.      * @exception SQLException if a database-access error occurs.
  126.      */
  127.     void setFloat(int parameterIndex, float x) throws SQLException;
  128.  
  129.     /**
  130.      * Set a parameter to a Java double value.  The driver converts this
  131.      * to a SQL DOUBLE value when it sends it to the database.
  132.      *
  133.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  134.      * @param x the parameter value
  135.      * @exception SQLException if a database-access error occurs.
  136.      */
  137.     void setDouble(int parameterIndex, double x) throws SQLException;
  138.  
  139.     /**
  140.      * Set a parameter to a java.lang.BigDecimal value.  
  141.      * The driver converts this to a SQL NUMERIC value when
  142.      * it sends it to the database.
  143.      *
  144.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  145.      * @param x the parameter value
  146.      * @exception SQLException if a database-access error occurs.
  147.      */
  148.     void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException;
  149.  
  150.     /**
  151.      * Set a parameter to a Java String value.  The driver converts this
  152.      * to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments
  153.      * size relative to the driver's limits on VARCHARs) when it sends
  154.      * it to the database.
  155.      *
  156.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  157.      * @param x the parameter value
  158.      * @exception SQLException if a database-access error occurs.
  159.      */
  160.     void setString(int parameterIndex, String x) throws SQLException;
  161.  
  162.     /**
  163.      * Set a parameter to a Java array of bytes.  The driver converts
  164.      * this to a SQL VARBINARY or LONGVARBINARY (depending on the
  165.      * argument's size relative to the driver's limits on VARBINARYs)
  166.      * when it sends it to the database.
  167.      *
  168.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  169.      * @param x the parameter value 
  170.      * @exception SQLException if a database-access error occurs.
  171.      */
  172.     void setBytes(int parameterIndex, byte x[]) throws SQLException;
  173.  
  174.     /**
  175.      * Set a parameter to a java.sql.Date value.  The driver converts this
  176.      * to a SQL DATE value when it sends it to the database.
  177.      *
  178.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  179.      * @param x the parameter value
  180.      * @exception SQLException if a database-access error occurs.
  181.      */
  182.     void setDate(int parameterIndex, java.sql.Date x)
  183.         throws SQLException;
  184.  
  185.     /**
  186.      * Set a parameter to a java.sql.Time value.  The driver converts this
  187.      * to a SQL TIME value when it sends it to the database.
  188.      *
  189.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  190.      * @param x the parameter value
  191.      * @exception SQLException if a database-access error occurs.
  192.      */
  193.     void setTime(int parameterIndex, java.sql.Time x) 
  194.         throws SQLException;
  195.  
  196.     /**
  197.      * Set a parameter to a java.sql.Timestamp value.  The driver
  198.      * converts this to a SQL TIMESTAMP value when it sends it to the
  199.      * database.
  200.      *
  201.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  202.      * @param x the parameter value 
  203.      * @exception SQLException if a database-access error occurs.
  204.      */
  205.     void setTimestamp(int parameterIndex, java.sql.Timestamp x)
  206.         throws SQLException;
  207.  
  208.     /**
  209.      * When a very large ASCII value is input to a LONGVARCHAR
  210.      * parameter, it may be more practical to send it via a
  211.      * java.io.InputStream. JDBC will read the data from the stream
  212.      * as needed, until it reaches end-of-file.  The JDBC driver will
  213.      * do any necessary conversion from ASCII to the database char format.
  214.      * 
  215.      * <P><B>Note:</B> This stream object can either be a standard
  216.      * Java stream object or your own subclass that implements the
  217.      * standard interface.
  218.      *
  219.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  220.      * @param x the java input stream which contains the ASCII parameter value
  221.      * @param length the number of bytes in the stream 
  222.      * @exception SQLException if a database-access error occurs.
  223.      */
  224.     void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)
  225.         throws SQLException;
  226.  
  227.     /**
  228.      * When a very large UNICODE value is input to a LONGVARCHAR
  229.      * parameter, it may be more practical to send it via a
  230.      * java.io.InputStream. JDBC will read the data from the stream
  231.      * as needed, until it reaches end-of-file.  The JDBC driver will
  232.      * do any necessary conversion from UNICODE to the database char format.
  233.      * 
  234.      * <P><B>Note:</B> This stream object can either be a standard
  235.      * Java stream object or your own subclass that implements the
  236.      * standard interface.
  237.      *
  238.      * @param parameterIndex the first parameter is 1, the second is 2, ...  
  239.      * @param x the java input stream which contains the
  240.      * UNICODE parameter value 
  241.      * @param length the number of bytes in the stream 
  242.      * @exception SQLException if a database-access error occurs.
  243.      */
  244.     void setUnicodeStream(int parameterIndex, java.io.InputStream x, int length)
  245.         throws SQLException;
  246.  
  247.     /**
  248.      * When a very large binary value is input to a LONGVARBINARY
  249.      * parameter, it may be more practical to send it via a
  250.      * java.io.InputStream. JDBC will read the data from the stream
  251.      * as needed, until it reaches end-of-file.
  252.      * 
  253.      * <P><B>Note:</B> This stream object can either be a standard
  254.      * Java stream object or your own subclass that implements the
  255.      * standard interface.
  256.      *
  257.      * @param parameterIndex the first parameter is 1, the second is 2, ...
  258.      * @param x the java input stream which contains the binary parameter value
  259.      * @param length the number of bytes in the stream 
  260.      * @exception SQLException if a database-access error occurs.
  261.      */
  262.     void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) 
  263.         throws SQLException;
  264.  
  265.     /**
  266.      * <P>In general, parameter values remain in force for repeated use of a
  267.      * Statement. Setting a parameter value automatically clears its
  268.      * previous value.  However, in some cases it is useful to immediately
  269.      * release the resources used by the current parameter values; this can
  270.      * be done by calling clearParameters.
  271.      *
  272.      * @exception SQLException if a database-access error occurs.
  273.      */
  274.     void clearParameters() throws SQLException;
  275.  
  276.     //----------------------------------------------------------------------
  277.     // Advanced features:
  278.  
  279.     /**
  280.      * <p>Set the value of a parameter using an object; use the
  281.      * java.lang equivalent objects for integral values.
  282.      *
  283.      * <p>The given Java object will be converted to the targetSqlType
  284.      * before being sent to the database.
  285.      *
  286.      * <p>Note that this method may be used to pass datatabase-
  287.      * specific abstract data types. This is done by using a Driver-
  288.      * specific Java type and using a targetSqlType of
  289.      * java.sql.types.OTHER.
  290.      *
  291.      * @param parameterIndex The first parameter is 1, the second is 2, ...
  292.      * @param x The object containing the input parameter value
  293.      * @param targetSqlType The SQL type (as defined in java.sql.Types) to be 
  294.      * sent to the database. The scale argument may further qualify this type.
  295.      * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types
  296.      *          this is the number of digits after the decimal.  For all other
  297.      *          types this value will be ignored,
  298.      * @exception SQLException if a database-access error occurs.
  299.      * @see Types 
  300.      */
  301.     void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
  302.             throws SQLException;
  303.  
  304.    /**
  305.      * This method is like setObject above, but assumes a scale of zero.
  306.      *
  307.      * @exception SQLException if a database-access error occurs.
  308.      */
  309.     void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException;
  310.  
  311.     /**
  312.      * <p>Set the value of a parameter using an object; use the
  313.      * java.lang equivalent objects for integral values.
  314.      *
  315.      * <p>The JDBC specification specifies a standard mapping from
  316.      * Java Object types to SQL types.  The given argument java object
  317.      * will be converted to the corresponding SQL type before being
  318.      * sent to the database.
  319.      *
  320.      * <p>Note that this method may be used to pass datatabase
  321.      * specific abstract data types, by using a Driver specific Java
  322.      * type.
  323.      *
  324.      * @param parameterIndex The first parameter is 1, the second is 2, ...
  325.      * @param x The object containing the input parameter value 
  326.      * @exception SQLException if a database-access error occurs.
  327.      */
  328.     void setObject(int parameterIndex, Object x) throws SQLException;
  329.  
  330.     /**
  331.      * Some prepared statements return multiple results; the execute
  332.      * method handles these complex statements as well as the simpler
  333.      * form of statements handled by executeQuery and executeUpdate.
  334.      *
  335.      * @exception SQLException if a database-access error occurs.
  336.      * @see Statement#execute
  337.      */
  338.     boolean execute() throws SQLException;
  339. }
  340.