src/share/classes/java/sql/PreparedStatement.java

Print this page




 384     void clearParameters() throws SQLException;
 385 
 386     //----------------------------------------------------------------------
 387     // Advanced features:
 388 
 389    /**
 390     * Sets the value of the designated parameter with the given object.
 391     *
 392     * This method is similar to {@link #setObject(int parameterIndex,
 393     * Object x, int targetSqlType, int scaleOrLength)},
 394     * except that it assumes a scale of zero.
 395     *
 396     * @param parameterIndex the first parameter is 1, the second is 2, ...
 397     * @param x the object containing the input parameter value
 398     * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
 399     *                      sent to the database
 400     * @exception SQLException if parameterIndex does not correspond to a parameter
 401     * marker in the SQL statement; if a database access error occurs or this
 402     * method is called on a closed PreparedStatement
 403     * @exception SQLFeatureNotSupportedException if
 404     * the JDBC driver does not support this data type
 405     * @see Types
 406     */
 407     void setObject(int parameterIndex, Object x, int targetSqlType)
 408       throws SQLException;
 409 
 410     /**
 411      * <p>Sets the value of the designated parameter using the given object.
 412      *
 413      * <p>The JDBC specification specifies a standard mapping from
 414      * Java <code>Object</code> types to SQL types.  The given argument
 415      * will be converted to the corresponding SQL type before being
 416      * sent to the database.
 417      *
 418      * <p>Note that this method may be used to pass datatabase-
 419      * specific abstract data types, by using a driver-specific Java
 420      * type.
 421      *
 422      * If the object is of a class implementing the interface <code>SQLData</code>,
 423      * the JDBC driver should call the method <code>SQLData.writeSQL</code>
 424      * to write it to the SQL data stream.


 934      * abstract data types.
 935      *
 936      * @param parameterIndex the first parameter is 1, the second is 2, ...
 937      * @param x the object containing the input parameter value
 938      * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
 939      * sent to the database. The scale argument may further qualify this type.
 940      * @param scaleOrLength for <code>java.sql.Types.DECIMAL</code>
 941      *          or <code>java.sql.Types.NUMERIC types</code>,
 942      *          this is the number of digits after the decimal point. For
 943      *          Java Object types <code>InputStream</code> and <code>Reader</code>,
 944      *          this is the length
 945      *          of the data in the stream or reader.  For all other types,
 946      *          this value will be ignored.
 947      * @exception SQLException if parameterIndex does not correspond to a parameter
 948      * marker in the SQL statement; if a database access error occurs;
 949      * this method is called on a closed <code>PreparedStatement</code> or
 950      *            if the Java Object specified by x is an InputStream
 951      *            or Reader object and the value of the scale parameter is less
 952      *            than zero
 953      * @exception SQLFeatureNotSupportedException if
 954      * the JDBC driver does not support this data type
 955      * @see Types
 956      *
 957      */
 958     void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)
 959             throws SQLException;
 960    /**
 961      * Sets the designated parameter to the given input stream, which will have
 962      * the specified number of bytes.
 963      * When a very large ASCII value is input to a <code>LONGVARCHAR</code>
 964      * parameter, it may be more practical to send it via a
 965      * <code>java.io.InputStream</code>. Data will be read from the stream
 966      * as needed until end-of-file is reached.  The JDBC driver will
 967      * do any necessary conversion from ASCII to the database char format.
 968      *
 969      * <P><B>Note:</B> This stream object can either be a standard
 970      * Java stream object or your own subclass that implements the
 971      * standard interface.
 972      *
 973      * @param parameterIndex the first parameter is 1, the second is 2, ...
 974      * @param x the Java input stream that contains the ASCII parameter value


1238      * The default implementation will throw {@code SQLFeatureNotSupportedException}
1239      *
1240      * @param parameterIndex the first parameter is 1, the second is 2, ...
1241      * @param x the object containing the input parameter value
1242      * @param targetSqlType the SQL type to be sent to the database. The
1243      * scale argument may further qualify this type.
1244      * @param scaleOrLength for {@code java.sql.JDBCType.DECIMAL}
1245      *          or {@code java.sql.JDBCType.NUMERIC types},
1246      *          this is the number of digits after the decimal point. For
1247      *          Java Object types {@code InputStream} and {@code Reader},
1248      *          this is the length
1249      *          of the data in the stream or reader.  For all other types,
1250      *          this value will be ignored.
1251      * @exception SQLException if parameterIndex does not correspond to a
1252      * parameter marker in the SQL statement; if a database access error occurs
1253      * or this method is called on a closed {@code PreparedStatement}  or
1254      *            if the Java Object specified by x is an InputStream
1255      *            or Reader object and the value of the scale parameter is less
1256      *            than zero
1257      * @exception SQLFeatureNotSupportedException if
1258      * the JDBC driver does not support this data type
1259      * @see JDBCType
1260      * @see SQLType
1261      * @since 1.8
1262      */
1263     default void setObject(int parameterIndex, Object x, SQLType targetSqlType,
1264              int scaleOrLength) throws SQLException {
1265         throw new SQLFeatureNotSupportedException("setObject not implemented");
1266     }
1267 
1268     /**
1269      * Sets the value of the designated parameter with the given object.
1270      *
1271      * This method is similar to {@link #setObject(int parameterIndex,
1272      * Object x, SQLType targetSqlType, int scaleOrLength)},
1273      * except that it assumes a scale of zero.
1274      *<P>
1275      * The default implementation will throw {@code SQLFeatureNotSupportedException}
1276      *
1277      * @param parameterIndex the first parameter is 1, the second is 2, ...
1278      * @param x the object containing the input parameter value
1279      * @param targetSqlType the SQL type to be sent to the database
1280      * @exception SQLException if parameterIndex does not correspond to a
1281      * parameter marker in the SQL statement; if a database access error occurs
1282      * or this method is called on a closed {@code PreparedStatement}
1283      * @exception SQLFeatureNotSupportedException if
1284      * the JDBC driver does not support this data type
1285      * @see JDBCType
1286      * @see SQLType
1287      * @since 1.8
1288      */
1289     default void setObject(int parameterIndex, Object x, SQLType targetSqlType)
1290       throws SQLException {
1291         throw new SQLFeatureNotSupportedException("setObject not implemented");
1292     }
1293 
1294     /**
1295      * Executes the SQL statement in this <code>PreparedStatement</code> object,
1296      * which must be an SQL Data Manipulation Language (DML) statement,
1297      * such as <code>INSERT</code>, <code>UPDATE</code> or
1298      * <code>DELETE</code>; or an SQL statement that returns nothing,
1299      * such as a DDL statement.
1300      * <p>
1301      * This method should be used when the returned row count may exceed
1302      * {@link Integer#MAX_VALUE}.
1303      * <p>
1304      * The default implementation will throw {@code UnsupportedOperationException}


 384     void clearParameters() throws SQLException;
 385 
 386     //----------------------------------------------------------------------
 387     // Advanced features:
 388 
 389    /**
 390     * Sets the value of the designated parameter with the given object.
 391     *
 392     * This method is similar to {@link #setObject(int parameterIndex,
 393     * Object x, int targetSqlType, int scaleOrLength)},
 394     * except that it assumes a scale of zero.
 395     *
 396     * @param parameterIndex the first parameter is 1, the second is 2, ...
 397     * @param x the object containing the input parameter value
 398     * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
 399     *                      sent to the database
 400     * @exception SQLException if parameterIndex does not correspond to a parameter
 401     * marker in the SQL statement; if a database access error occurs or this
 402     * method is called on a closed PreparedStatement
 403     * @exception SQLFeatureNotSupportedException if
 404     * the JDBC driver does not support the specified targetSqlType
 405     * @see Types
 406     */
 407     void setObject(int parameterIndex, Object x, int targetSqlType)
 408       throws SQLException;
 409 
 410     /**
 411      * <p>Sets the value of the designated parameter using the given object.
 412      *
 413      * <p>The JDBC specification specifies a standard mapping from
 414      * Java <code>Object</code> types to SQL types.  The given argument
 415      * will be converted to the corresponding SQL type before being
 416      * sent to the database.
 417      *
 418      * <p>Note that this method may be used to pass datatabase-
 419      * specific abstract data types, by using a driver-specific Java
 420      * type.
 421      *
 422      * If the object is of a class implementing the interface <code>SQLData</code>,
 423      * the JDBC driver should call the method <code>SQLData.writeSQL</code>
 424      * to write it to the SQL data stream.


 934      * abstract data types.
 935      *
 936      * @param parameterIndex the first parameter is 1, the second is 2, ...
 937      * @param x the object containing the input parameter value
 938      * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
 939      * sent to the database. The scale argument may further qualify this type.
 940      * @param scaleOrLength for <code>java.sql.Types.DECIMAL</code>
 941      *          or <code>java.sql.Types.NUMERIC types</code>,
 942      *          this is the number of digits after the decimal point. For
 943      *          Java Object types <code>InputStream</code> and <code>Reader</code>,
 944      *          this is the length
 945      *          of the data in the stream or reader.  For all other types,
 946      *          this value will be ignored.
 947      * @exception SQLException if parameterIndex does not correspond to a parameter
 948      * marker in the SQL statement; if a database access error occurs;
 949      * this method is called on a closed <code>PreparedStatement</code> or
 950      *            if the Java Object specified by x is an InputStream
 951      *            or Reader object and the value of the scale parameter is less
 952      *            than zero
 953      * @exception SQLFeatureNotSupportedException if
 954      * the JDBC driver does not support the specified targetSqlType
 955      * @see Types
 956      *
 957      */
 958     void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)
 959             throws SQLException;
 960    /**
 961      * Sets the designated parameter to the given input stream, which will have
 962      * the specified number of bytes.
 963      * When a very large ASCII value is input to a <code>LONGVARCHAR</code>
 964      * parameter, it may be more practical to send it via a
 965      * <code>java.io.InputStream</code>. Data will be read from the stream
 966      * as needed until end-of-file is reached.  The JDBC driver will
 967      * do any necessary conversion from ASCII to the database char format.
 968      *
 969      * <P><B>Note:</B> This stream object can either be a standard
 970      * Java stream object or your own subclass that implements the
 971      * standard interface.
 972      *
 973      * @param parameterIndex the first parameter is 1, the second is 2, ...
 974      * @param x the Java input stream that contains the ASCII parameter value


1238      * The default implementation will throw {@code SQLFeatureNotSupportedException}
1239      *
1240      * @param parameterIndex the first parameter is 1, the second is 2, ...
1241      * @param x the object containing the input parameter value
1242      * @param targetSqlType the SQL type to be sent to the database. The
1243      * scale argument may further qualify this type.
1244      * @param scaleOrLength for {@code java.sql.JDBCType.DECIMAL}
1245      *          or {@code java.sql.JDBCType.NUMERIC types},
1246      *          this is the number of digits after the decimal point. For
1247      *          Java Object types {@code InputStream} and {@code Reader},
1248      *          this is the length
1249      *          of the data in the stream or reader.  For all other types,
1250      *          this value will be ignored.
1251      * @exception SQLException if parameterIndex does not correspond to a
1252      * parameter marker in the SQL statement; if a database access error occurs
1253      * or this method is called on a closed {@code PreparedStatement}  or
1254      *            if the Java Object specified by x is an InputStream
1255      *            or Reader object and the value of the scale parameter is less
1256      *            than zero
1257      * @exception SQLFeatureNotSupportedException if
1258      * the JDBC driver does not support the specified targetSqlType
1259      * @see JDBCType
1260      * @see SQLType
1261      * @since 1.8
1262      */
1263     default void setObject(int parameterIndex, Object x, SQLType targetSqlType,
1264              int scaleOrLength) throws SQLException {
1265         throw new SQLFeatureNotSupportedException("setObject not implemented");
1266     }
1267 
1268     /**
1269      * Sets the value of the designated parameter with the given object.
1270      *
1271      * This method is similar to {@link #setObject(int parameterIndex,
1272      * Object x, SQLType targetSqlType, int scaleOrLength)},
1273      * except that it assumes a scale of zero.
1274      *<P>
1275      * The default implementation will throw {@code SQLFeatureNotSupportedException}
1276      *
1277      * @param parameterIndex the first parameter is 1, the second is 2, ...
1278      * @param x the object containing the input parameter value
1279      * @param targetSqlType the SQL type to be sent to the database
1280      * @exception SQLException if parameterIndex does not correspond to a
1281      * parameter marker in the SQL statement; if a database access error occurs
1282      * or this method is called on a closed {@code PreparedStatement}
1283      * @exception SQLFeatureNotSupportedException if
1284      * the JDBC driver does not support the specified targetSqlType
1285      * @see JDBCType
1286      * @see SQLType
1287      * @since 1.8
1288      */
1289     default void setObject(int parameterIndex, Object x, SQLType targetSqlType)
1290       throws SQLException {
1291         throw new SQLFeatureNotSupportedException("setObject not implemented");
1292     }
1293 
1294     /**
1295      * Executes the SQL statement in this <code>PreparedStatement</code> object,
1296      * which must be an SQL Data Manipulation Language (DML) statement,
1297      * such as <code>INSERT</code>, <code>UPDATE</code> or
1298      * <code>DELETE</code>; or an SQL statement that returns nothing,
1299      * such as a DDL statement.
1300      * <p>
1301      * This method should be used when the returned row count may exceed
1302      * {@link Integer#MAX_VALUE}.
1303      * <p>
1304      * The default implementation will throw {@code UnsupportedOperationException}