Path: blob/master/src/java.sql/share/classes/java/sql/Clob.java
41153 views
/*1* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627import java.io.Reader;2829/**30* The mapping in the Java programming language31* for the SQL {@code CLOB} type.32* An SQL {@code CLOB} is a built-in type33* that stores a Character Large Object as a column value in a row of34* a database table.35* By default drivers implement a {@code Clob} object using an SQL36* {@code locator(CLOB)}, which means that a {@code Clob} object37* contains a logical pointer to the SQL {@code CLOB} data rather than38* the data itself. A {@code Clob} object is valid for the duration39* of the transaction in which it was created.40* <P>The {@code Clob} interface provides methods for getting the41* length of an SQL {@code CLOB} (Character Large Object) value,42* for materializing a {@code CLOB} value on the client, and for43* searching for a substring or {@code CLOB} object within a44* {@code CLOB} value.45* Methods in the interfaces {@link ResultSet},46* {@link CallableStatement}, and {@link PreparedStatement}, such as47* {@code getClob} and {@code setClob} allow a programmer to48* access an SQL {@code CLOB} value. In addition, this interface49* has methods for updating a {@code CLOB} value.50* <p>51* All methods on the {@code Clob} interface must be52* fully implemented if the JDBC driver supports the data type.53*54* @since 1.255*/5657public interface Clob {5859/**60* Retrieves the number of characters61* in the {@code CLOB} value62* designated by this {@code Clob} object.63*64* @return length of the {@code CLOB} in characters65* @throws SQLException if there is an error accessing the66* length of the {@code CLOB} value67* @throws SQLFeatureNotSupportedException if the JDBC driver68* does not support this method69* @since 1.270*/71long length() throws SQLException;7273/**74* Retrieves a copy of the specified substring75* in the {@code CLOB} value76* designated by this {@code Clob} object.77* The substring begins at position78* {@code pos} and has up to {@code length} consecutive79* characters.80*81* @param pos the first character of the substring to be extracted.82* The first character is at position 1.83* @param length the number of consecutive characters to be copied;84* the value for length must be 0 or greater85* @return a {@code String} that is the specified substring in86* the {@code CLOB} value designated by this {@code Clob} object87* @throws SQLException if there is an error accessing the88* {@code CLOB} value; if pos is less than 1 or length is89* less than 090* @throws SQLFeatureNotSupportedException if the JDBC driver91* does not support this method92* @since 1.293*/94String getSubString(long pos, int length) throws SQLException;9596/**97* Retrieves the {@code CLOB} value designated by this {@code Clob}98* object as a {@code java.io.Reader} object (or as a stream of99* characters).100*101* @return a {@code java.io.Reader} object containing the102* {@code CLOB} data103* @throws SQLException if there is an error accessing the104* {@code CLOB} value105* @throws SQLFeatureNotSupportedException if the JDBC driver106* does not support this method107* @see #setCharacterStream108* @since 1.2109*/110java.io.Reader getCharacterStream() throws SQLException;111112/**113* Retrieves the {@code CLOB} value designated by this {@code Clob}114* object as an ascii stream.115*116* @return a {@code java.io.InputStream} object containing the117* {@code CLOB} data118* @throws SQLException if there is an error accessing the119* {@code CLOB} value120* @throws SQLFeatureNotSupportedException if the JDBC driver121* does not support this method122* @see #setAsciiStream123* @since 1.2124*/125java.io.InputStream getAsciiStream() throws SQLException;126127/**128* Retrieves the character position at which the specified substring129* {@code searchstr} appears in the SQL {@code CLOB} value130* represented by this {@code Clob} object. The search131* begins at position {@code start}.132*133* @param searchstr the substring for which to search134* @param start the position at which to begin searching;135* the first position is 1136* @return the position at which the substring appears or -1 if it is not137* present; the first position is 1138* @throws SQLException if there is an error accessing the139* {@code CLOB} value or if pos is less than 1140* @throws SQLFeatureNotSupportedException if the JDBC driver141* does not support this method142* @since 1.2143*/144long position(String searchstr, long start) throws SQLException;145146/**147* Retrieves the character position at which the specified148* {@code Clob} object {@code searchstr} appears in this149* {@code Clob} object. The search begins at position150* {@code start}.151*152* @param searchstr the {@code Clob} object for which to search153* @param start the position at which to begin searching; the first154* position is 1155* @return the position at which the {@code Clob} object appears156* or -1 if it is not present; the first position is 1157* @throws SQLException if there is an error accessing the158* {@code CLOB} value or if start is less than 1159* @throws SQLFeatureNotSupportedException if the JDBC driver160* does not support this method161* @since 1.2162*/163long position(Clob searchstr, long start) throws SQLException;164165//---------------------------- jdbc 3.0 -----------------------------------166167/**168* Writes the given Java {@code String} to the {@code CLOB}169* value that this {@code Clob} object designates at the position170* {@code pos}. The string will overwrite the existing characters171* in the {@code Clob} object starting at the position172* {@code pos}. If the end of the {@code Clob} value is reached173* while writing the given string, then the length of the {@code Clob}174* value will be increased to accommodate the extra characters.175* <p>176* <b>Note:</b> If the value specified for {@code pos}177* is greater than the length+1 of the {@code CLOB} value then the178* behavior is undefined. Some JDBC drivers may throw an179* {@code SQLException} while other drivers may support this180* operation.181*182* @param pos the position at which to start writing to the {@code CLOB}183* value that this {@code Clob} object represents;184* the first position is 1.185* @param str the string to be written to the {@code CLOB}186* value that this {@code Clob} designates187* @return the number of characters written188* @throws SQLException if there is an error accessing the189* {@code CLOB} value or if pos is less than 1190*191* @throws SQLFeatureNotSupportedException if the JDBC driver192* does not support this method193* @since 1.4194*/195int setString(long pos, String str) throws SQLException;196197/**198* Writes {@code len} characters of {@code str}, starting199* at character {@code offset}, to the {@code CLOB} value200* that this {@code Clob} represents.201* The string will overwrite the existing characters202* in the {@code Clob} object starting at the position203* {@code pos}. If the end of the {@code Clob} value is reached204* while writing the given string, then the length of the {@code Clob}205* value will be increased to accommodate the extra characters.206* <p>207* <b>Note:</b> If the value specified for {@code pos}208* is greater than the length+1 of the {@code CLOB} value then the209* behavior is undefined. Some JDBC drivers may throw an210* {@code SQLException} while other drivers may support this211* operation.212*213* @param pos the position at which to start writing to this214* {@code CLOB} object; The first position is 1215* @param str the string to be written to the {@code CLOB}216* value that this {@code Clob} object represents217* @param offset the offset into {@code str} to start reading218* the characters to be written219* @param len the number of characters to be written220* @return the number of characters written221* @throws SQLException if there is an error accessing the222* {@code CLOB} value or if pos is less than 1223*224* @throws SQLFeatureNotSupportedException if the JDBC driver225* does not support this method226* @since 1.4227*/228int setString(long pos, String str, int offset, int len) throws SQLException;229230/**231* Retrieves a stream to be used to write Ascii characters to the232* {@code CLOB} value that this {@code Clob} object represents,233* starting at position {@code pos}. Characters written to the stream234* will overwrite the existing characters235* in the {@code Clob} object starting at the position236* {@code pos}. If the end of the {@code Clob} value is reached237* while writing characters to the stream, then the length of the {@code Clob}238* value will be increased to accommodate the extra characters.239* <p>240* <b>Note:</b> If the value specified for {@code pos}241* is greater than the length+1 of the {@code CLOB} value then the242* behavior is undefined. Some JDBC drivers may throw an243* {@code SQLException} while other drivers may support this244* operation.245*246* @param pos the position at which to start writing to this247* {@code CLOB} object; The first position is 1248* @return the stream to which ASCII encoded characters can be written249* @throws SQLException if there is an error accessing the250* {@code CLOB} value or if pos is less than 1251* @throws SQLFeatureNotSupportedException if the JDBC driver252* does not support this method253* @see #getAsciiStream254*255* @since 1.4256*/257java.io.OutputStream setAsciiStream(long pos) throws SQLException;258259/**260* Retrieves a stream to be used to write a stream of Unicode characters261* to the {@code CLOB} value that this {@code Clob} object262* represents, at position {@code pos}. Characters written to the stream263* will overwrite the existing characters264* in the {@code Clob} object starting at the position265* {@code pos}. If the end of the {@code Clob} value is reached266* while writing characters to the stream, then the length of the {@code Clob}267* value will be increased to accommodate the extra characters.268* <p>269* <b>Note:</b> If the value specified for {@code pos}270* is greater than the length+1 of the {@code CLOB} value then the271* behavior is undefined. Some JDBC drivers may throw an272* {@code SQLException} while other drivers may support this273* operation.274*275* @param pos the position at which to start writing to the276* {@code CLOB} value; The first position is 1277*278* @return a stream to which Unicode encoded characters can be written279* @throws SQLException if there is an error accessing the280* {@code CLOB} value or if pos is less than 1281* @throws SQLFeatureNotSupportedException if the JDBC driver282* does not support this method283* @see #getCharacterStream284*285* @since 1.4286*/287java.io.Writer setCharacterStream(long pos) throws SQLException;288289/**290* Truncates the {@code CLOB} value that this {@code Clob}291* designates to have a length of {@code len}292* characters.293* <p>294* <b>Note:</b> If the value specified for {@code pos}295* is greater than the length+1 of the {@code CLOB} value then the296* behavior is undefined. Some JDBC drivers may throw an297* {@code SQLException} while other drivers may support this298* operation.299*300* @param len the length, in characters, to which the {@code CLOB} value301* should be truncated302* @throws SQLException if there is an error accessing the303* {@code CLOB} value or if len is less than 0304*305* @throws SQLFeatureNotSupportedException if the JDBC driver306* does not support this method307* @since 1.4308*/309void truncate(long len) throws SQLException;310311/**312* This method releases the resources that the {@code Clob} object313* holds. The object is invalid once the {@code free} method314* is called.315* <p>316* After {@code free} has been called, any attempt to invoke a317* method other than {@code free} will result in a {@code SQLException}318* being thrown. If {@code free} is called multiple times, the subsequent319* calls to {@code free} are treated as a no-op.320*321* @throws SQLException if an error occurs releasing322* the Clob's resources323*324* @throws SQLFeatureNotSupportedException if the JDBC driver325* does not support this method326* @since 1.6327*/328void free() throws SQLException;329330/**331* Returns a {@code Reader} object that contains332* a partial {@code Clob} value, starting with the character333* specified by pos, which is length characters in length.334*335* @param pos the offset to the first character of the partial value to336* be retrieved. The first character in the Clob is at position 1.337* @param length the length in characters of the partial value to be retrieved.338* @return {@code Reader} through which339* the partial {@code Clob} value can be read.340* @throws SQLException if pos is less than 1;341* or if pos is greater than the number of characters342* in the {@code Clob};343* or if pos + length is greater than the number of344* characters in the {@code Clob}345*346* @throws SQLFeatureNotSupportedException if the JDBC driver347* does not support this method348* @since 1.6349*/350Reader getCharacterStream(long pos, long length) throws SQLException;351352}353354355