home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / sql / PreparedStatement.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  15.4 KB  |  446 lines

  1. /*
  2.  * @(#)PreparedStatement.java    1.14 98/03/18
  3.  *
  4.  * Copyright 1996-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.math.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.  * @deprecated
  244.  */
  245. void setUnicodeStream(int parameterIndex, java.io.InputStream x, 
  246.           int length) throws SQLException;
  247.  
  248. /**
  249.  * When a very large binary value is input to a LONGVARBINARY
  250.  * parameter, it may be more practical to send it via a
  251.  * java.io.InputStream. JDBC will read the data from the stream
  252.  * as needed, until it reaches end-of-file.
  253.  * 
  254.  * <P><B>Note:</B> This stream object can either be a standard
  255.  * Java stream object or your own subclass that implements the
  256.  * standard interface.
  257.  *
  258.  * @param parameterIndex the first parameter is 1, the second is 2, ...
  259.  * @param x the java input stream which contains the binary parameter value
  260.  * @param length the number of bytes in the stream 
  261.  * @exception SQLException if a database-access error occurs.
  262.  */
  263. void setBinaryStream(int parameterIndex, java.io.InputStream x, 
  264.          int length) throws SQLException;
  265.  
  266. /**
  267.  * <P>In general, parameter values remain in force for repeated use of a
  268.  * Statement. Setting a parameter value automatically clears its
  269.  * previous value.  However, in some cases it is useful to immediately
  270.  * release the resources used by the current parameter values; this can
  271.  * be done by calling clearParameters.
  272.  *
  273.  * @exception SQLException if a database-access error occurs.
  274.  */
  275. void clearParameters() throws SQLException;
  276.  
  277. //----------------------------------------------------------------------
  278. // Advanced features:
  279.  
  280. /**
  281.  * <p>Set the value of a parameter using an object; use the
  282.  * java.lang equivalent objects for integral values.
  283.  *
  284.  * <p>The given Java object will be converted to the targetSqlType
  285.  * before being sent to the database.
  286.  *
  287.  * <p>Note that this method may be used to pass datatabase-
  288.  * specific abstract data types. This is done by using a Driver-
  289.  * specific Java type and using a targetSqlType of
  290.  * java.sql.types.OTHER.
  291.  *
  292.  * @param parameterIndex The first parameter is 1, the second is 2, ...
  293.  * @param x The object containing the input parameter value
  294.  * @param targetSqlType The SQL type (as defined in java.sql.Types) to be 
  295.  * sent to the database. The scale argument may further qualify this type.
  296.  * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types
  297.  *          this is the number of digits after the decimal.  For all other
  298.  *          types this value will be ignored,
  299.  * @exception SQLException if a database-access error occurs.
  300.  * @see Types 
  301.  */
  302. void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
  303.         throws SQLException;
  304.  
  305. /**
  306.  * This method is like setObject above, but assumes a scale of zero.
  307.  *
  308.  * @exception SQLException if a database-access error occurs.
  309.  */
  310. void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException;
  311.  
  312. /**
  313.  * <p>Set the value of a parameter using an object; use the
  314.  * java.lang equivalent objects for integral values.
  315.  *
  316.  * <p>The JDBC specification specifies a standard mapping from
  317.  * Java Object types to SQL types.  The given argument java object
  318.  * will be converted to the corresponding SQL type before being
  319.  * sent to the database.
  320.  *
  321.  * <p>Note that this method may be used to pass datatabase
  322.  * specific abstract data types, by using a Driver specific Java
  323.  * type.
  324.  *
  325.  * @param parameterIndex The first parameter is 1, the second is 2, ...
  326.  * @param x The object containing the input parameter value 
  327.  * @exception SQLException if a database-access error occurs.
  328.  */
  329. void setObject(int parameterIndex, Object x) throws SQLException;
  330.  
  331. /**
  332.  * Some prepared statements return multiple results; the execute
  333.  * method handles these complex statements as well as the simpler
  334.  * form of statements handled by executeQuery and executeUpdate.
  335.  *
  336.  * @exception SQLException if a database-access error occurs.
  337.  * @see Statement#execute
  338.  */
  339. boolean execute() throws SQLException;
  340.  
  341. //--------------------------JDBC 2.0-----------------------------
  342.  
  343. /**
  344.  * JDBC 2.0
  345.  *
  346.  * Add a set of parameters to the batch.
  347.  * 
  348.  * @exception SQLException if a database-access error occurs.
  349.  * @see Statement#addBatch
  350.  */
  351. void addBatch() throws SQLException;
  352.  
  353. /**
  354.  * JDBC 2.0
  355.  *
  356.  * When a very large UNICODE value is input to a LONGVARCHAR
  357.  * parameter, it may be more practical to send it via a
  358.  * java.io.Reader. JDBC will read the data from the stream
  359.  * as needed, until it reaches end-of-file.  The JDBC driver will
  360.  * do any necessary conversion from UNICODE to the database char format.
  361.  * 
  362.  * <P><B>Note:</B> This stream object can either be a standard
  363.  * Java stream object or your own subclass that implements the
  364.  * standard interface.
  365.  *
  366.  * @param parameterIndex the first parameter is 1, the second is 2, ...
  367.  * @param x the java reader which contains the UNICODE data
  368.  * @param length the number of characters in the stream 
  369.  * @exception SQLException if a database-access error occurs.
  370.  */
  371. void setCharacterStream(int parameterIndex,
  372.               java.io.Reader reader,
  373.           int length) throws SQLException;
  374.  
  375. /**
  376. * When the parameter x is a UDT value, the JDBC driver will
  377. * act as follows:
  378. *
  379. * If the object is of a class implementing SQLData,
  380. * then call its method writeSQL to write it to the SQL data stream.
  381. * else
  382. * If the object is of a class implementing Ref, BlobLocator,
  383. * ClobLocator, StructLocator, or ArrayLocator then
  384. * pass it to the database as a value of the corresponding SQL type.
  385. *
  386. * Raise an exception if there is an ambiguity, for example, if the
  387. * object is of a class implementing more than one of those interfaces.
  388. *
  389. * @param i the first parameter is 1, the second is 2, ...
  390. * @param x an value to be passed to SQL
  391. void setObject (int i, Object x) throws SQLException;
  392. */
  393.  
  394. /**
  395. * Set a REF(<structured-type>) parameter.
  396. *
  397. * @param i the first parameter is 1, the second is 2, ...
  398. * @param x an object representing data of an SQL REF Type
  399. */
  400. void setRef (int i, Ref x) throws SQLException;
  401.  
  402.   /**
  403.   * Set a LOCATOR(BLOB) parameter.
  404.   *
  405.   * @param i the first parameter is 1, the second is 2, ...
  406.   * @param x an object representing data of a locator to a BLOB
  407.   */
  408.   void setBlobLocator (int i, BlobLocator x) throws SQLException;
  409.  
  410.   /**
  411.   * Set a LOCATOR(CLOB) parameter.
  412.   *
  413.   * @param i the first parameter is 1, the second is 2, ...
  414.   * @param x an object representing data of a locator to a CLOB
  415.   */
  416.   void setClobLocator (int i, ClobLocator x) throws SQLException;
  417.  
  418.   /**
  419.   * Set a LOCATOR(<structured-type>) parameter.
  420.   *
  421.   * @param i the first parameter is 1, the second is 2, ...
  422.   * @param x an object representing data of a locator to an instance
  423.   * of a Structured Type
  424.   */
  425.   void setStructLocator (int i, StructLocator x) throws SQLException;
  426.  
  427.   /**
  428.   * Set a LOCATOR(<array>) parameter.
  429.   *
  430.   * @param i the first parameter is 1, the second is 2, ...
  431.   * @param x an object representing data of a locator to an SQL array
  432.   */
  433.   void setArrayLocator (int i, ArrayLocator x) throws SQLException;
  434.  
  435. }
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.