Package com.microsoft.sqlserver.jdbc
Class SQLServerNClob
- java.lang.Object
-
- com.microsoft.sqlserver.jdbc.SQLServerNClob
-
- All Implemented Interfaces:
java.io.Serializable
,java.sql.Clob
,java.sql.NClob
public final class SQLServerNClob extends java.lang.Object implements java.sql.NClob
Represents a National Character Set LOB object and implements java.sql.NClob.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
delayLoadingLob
protected com.microsoft.sqlserver.jdbc.TypeInfo
typeInfo
protected java.lang.String
value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
free()
Frees this Clob/NClob object and releases the resources that it holds.java.io.InputStream
getAsciiStream()
Returns the CLOB as an ASCII stream.java.io.Reader
getCharacterStream()
Returns the CLOB value designated by this Clob object as a java.io.Reader object (or as a stream of characters).java.io.Reader
getCharacterStream(long pos, long length)
Returns the Clob data as a java.io.Reader object or as a stream of characters with the specified position and length.java.lang.String
getSubString(long pos, int length)
Returns a copy of the specified substring in the CLOB value designated by this Clob object.long
length()
Returns the number of characters in the CLOB value designated by this Clob object.long
position(java.lang.String searchstr, long start)
Returns the character position at which the specified substring searchstr appears in the SQL CLOB value represented by this Clob object.long
position(java.sql.Clob searchstr, long start)
Returns the character position at which the specified Clob object searchstr appears in this Clob object.java.io.OutputStream
setAsciiStream(long pos)
Returns a stream to be used to write Ascii characters to the CLOB value that this Clob object represents, starting at position pos.java.io.Writer
setCharacterStream(long pos)
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.protected void
setDefaultCharset(java.nio.charset.Charset c)
int
setString(long pos, java.lang.String s)
Writes the given Java String to the CLOB value that this Clob object designates at the position pos.int
setString(long pos, java.lang.String str, int offset, int len)
Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.java.lang.String
toString()
void
truncate(long len)
Truncates the CLOB value that this Clob designates to have a length of len characters.
-
-
-
Method Detail
-
getAsciiStream
public java.io.InputStream getAsciiStream() throws java.sql.SQLException
Returns the CLOB as an ASCII stream.- Specified by:
getAsciiStream
in interfacejava.sql.Clob
- Returns:
- the data as an input stream
- Throws:
java.sql.SQLException
- when an error occurs
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
free
public void free() throws java.sql.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:
java.sql.SQLException
- when an error occurs
-
getCharacterStream
public java.io.Reader getCharacterStream() throws java.sql.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:
java.sql.SQLException
- if there is an error accessing the CLOB value
-
getCharacterStream
public java.io.Reader getCharacterStream(long pos, long length) throws java.sql.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:
java.sql.SQLException
- when an error occurs.
-
getSubString
public java.lang.String getSubString(long pos, int length) throws java.sql.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:
java.sql.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 java.sql.SQLException
Returns the number of characters in the CLOB value designated by this Clob object.- Returns:
- length of the CLOB in characters
- Throws:
java.sql.SQLException
- when an error occurs
-
position
public long position(java.sql.Clob searchstr, long start) throws java.sql.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 searchstart
- - 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:
java.sql.SQLException
- - if there is an error accessing the CLOB value or if start is less than 1
-
position
public long position(java.lang.String searchstr, long start) throws java.sql.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 searchstart
- - 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:
java.sql.SQLException
- - if there is an error accessing the CLOB value or if start is less than 1
-
truncate
public void truncate(long len) throws java.sql.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:
java.sql.SQLException
- when an error occurs
-
setAsciiStream
public java.io.OutputStream setAsciiStream(long pos) throws java.sql.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:
java.sql.SQLException
- when an error occurs
-
setCharacterStream
public java.io.Writer setCharacterStream(long pos) throws java.sql.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:
java.sql.SQLException
- when an error occurs
-
setString
public int setString(long pos, java.lang.String s) throws java.sql.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 CLOBs
- the string to be written to the CLOB value that this Clob designates- Returns:
- the number of characters written
- Throws:
java.sql.SQLException
- when an error occurs
-
setString
public int setString(long pos, java.lang.String str, int offset, int len) throws java.sql.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 1str
- - the string to be written to the CLOB value that this Clob object representsoffset
- - the offset (0-based) into str to start reading the characters to be writtenlen
- - the number of characters to be written- Returns:
- the number of characters written
- Throws:
java.sql.SQLException
- - if there is an error accessing the CLOB value or if pos is less than 1
-
setDefaultCharset
protected void setDefaultCharset(java.nio.charset.Charset c)
-
-