Class SQLServerClob

java.lang.Object
com.microsoft.sqlserver.jdbc.SQLServerClob
All Implemented Interfaces:
Serializable, Clob

public class SQLServerClob extends Object implements Clob
Represents a character LOB object and implements java.sql.Clob.
See Also:
Serialized Form
  • Constructor Details

  • Method Details

    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • free

      public void free() throws SQLException
      Frees this Clob/NClob object and releases the resources that it holds. After free() has been called, any attempt to invoke a method other than free() will result in a SQLException being thrown. If free() is called multiple times, the subsequent calls to free are treated as a no-op.
      Throws:
      SQLException - when an error occurs
    • getAsciiStream

      public InputStream getAsciiStream() throws SQLException
      Returns the CLOB as an ASCII stream.
      Returns:
      the data as an input stream
      Throws:
      SQLException - when an error occurs
    • getCharacterStream

      public Reader getCharacterStream() throws SQLException
      Returns the CLOB value designated by this Clob object as a java.io.Reader object (or as a stream of characters).
      Returns:
      a java.io.Reader object containing the CLOB data
      Throws:
      SQLException - if there is an error accessing the CLOB value
    • getCharacterStream

      public Reader getCharacterStream(long pos, long length) throws SQLException
      Returns the Clob data as a java.io.Reader object or as a stream of characters with the specified position and length.
      Parameters:
      pos - A long that indicates the offset to the first character of the partial value to be retrieved.
      length - A long that indicates the length in characters of the partial value to be retrieved.
      Returns:
      A Reader object that contains the Clob data.
      Throws:
      SQLException - when an error occurs.
    • getSubString

      public String getSubString(long pos, int length) throws SQLException
      Returns a copy of the specified substring in the CLOB value designated by this Clob object. The substring begins at position pos and has up to length consecutive characters.
      Parameters:
      pos - - the first character of the substring to be extracted. The first character is at position 1.
      length - - the number of consecutive characters to be copied; the value for length must be 0 or greater
      Returns:
      a String that is the specified substring in the CLOB value designated by this Clob object
      Throws:
      SQLException - - if there is an error accessing the CLOB value; if pos is less than 1 or length is less than 0
    • length

      public long length() throws SQLException
      Returns the number of characters in the CLOB value designated by this Clob object.
      Returns:
      length of the CLOB in characters
      Throws:
      SQLException - when an error occurs
    • position

      public long position(Clob searchstr, long start) throws SQLException
      Returns the character position at which the specified Clob object searchstr appears in this Clob object. The search begins at position start.
      Parameters:
      searchstr - - the Clob for which to search
      start - - the position at which to begin searching; the first position is 1
      Returns:
      the position at which the Clob object appears or -1 if it is not present; the first position is 1
      Throws:
      SQLException - - if there is an error accessing the CLOB value or if start is less than 1
    • position

      public long position(String searchstr, long start) throws SQLException
      Returns the character position at which the specified substring searchstr appears in the SQL CLOB value represented by this Clob object. The search begins at position start.
      Parameters:
      searchstr - - the substring for which to search
      start - - the position at which to begin searching; the first position is 1
      Returns:
      the position at which the substring appears or -1 if it is not present; the first position is 1
      Throws:
      SQLException - - if there is an error accessing the CLOB value or if start is less than 1
    • truncate

      public void truncate(long len) throws SQLException
      Truncates the CLOB value that this Clob designates to have a length of len characters.
      Parameters:
      len - the length, in characters, to which the CLOB value should be truncated
      Throws:
      SQLException - when an error occurs
    • setAsciiStream

      public OutputStream setAsciiStream(long pos) throws SQLException
      Returns a stream to be used to write Ascii characters to the CLOB value that this Clob object represents, starting at position pos.
      Parameters:
      pos - the position at which to start writing to this CLOB object
      Returns:
      the stream to which ASCII encoded characters can be written
      Throws:
      SQLException - when an error occurs
    • setCharacterStream

      public Writer setCharacterStream(long pos) throws SQLException
      Returns a stream to be used to write a stream of Unicode characters to the CLOB value that this Clob object represents, at position pos.
      Parameters:
      pos - the position at which to start writing to the CLOB value
      Returns:
      a stream to which Unicode encoded characters can be written
      Throws:
      SQLException - when an error occurs
    • setString

      public int setString(long pos, String s) throws SQLException
      Writes the given Java String to the CLOB value that this Clob object designates at the position pos.
      Parameters:
      pos - the position at which to start writing to the CLOB
      s - the string to be written to the CLOB value that this Clob designates
      Returns:
      the number of characters written
      Throws:
      SQLException - when an error occurs
    • setString

      public int setString(long pos, String str, int offset, int len) throws SQLException
      Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents. The string will overwrite the existing characters in the Clob object starting at the position pos. If the end of the Clob value is reached while writing the given string, then the length of the Clob value will be increased to accommodate the extra characters. SQL Server behavior: If the value specified for pos is greater than then length+1 of the CLOB value then a SQLException is thrown.
      Parameters:
      pos - - the position at which to start writing to this CLOB object; The first position is 1
      str - - the string to be written to the CLOB value that this Clob object represents
      offset - - the offset (0-based) into str to start reading the characters to be written
      len - - the number of characters to be written
      Returns:
      the number of characters written
      Throws:
      SQLException - - if there is an error accessing the CLOB value or if pos is less than 1
    • setDefaultCharset

      protected void setDefaultCharset(Charset c)
      Sets the default charset
      Parameters:
      c - charset