java.sql

Interface Clob

Known Implementing Classes:
ClobImpl, SerialClob, SerializableClob

public interface Clob

The mapping in the JavaTM programming language for the SQL CLOB type. An SQL CLOB is a built-in type that stores a Character Large Object as a column value in a row of a database table. By default drivers implement a Clob object using an SQL locator(CLOB), which means that a Clob object contains a logical pointer to the SQL CLOB data rather than the data itself. A Clob object is valid for the duration of the transaction in which it was created.

The Clob interface provides methods for getting the length of an SQL CLOB (Character Large Object) value, for materializing a CLOB value on the client, and for searching for a substring or CLOB object within a CLOB value. Methods in the interfaces ResultSet, CallableStatement, and PreparedStatement, such as getClob and setClob allow a programmer to access an SQL CLOB value. In addition, this interface has methods for updating a CLOB value.

Since:
1.2

Method Summary

InputStream
getAsciiStream()
Retrieves the CLOB value designated by this Clob object as an ascii stream.
Reader
getCharacterStream()
Retrieves the CLOB value designated by this Clob object as a java.io.Reader object (or as a stream of characters).
String
getSubString(long pos, int length)
Retrieves a copy of the specified substring in the CLOB value designated by this Clob object.
long
length()
Retrieves the number of characters in the CLOB value designated by this Clob object.
long
position(String searchstr, long start)
Retrieves the character position at which the specified substring searchstr appears in the SQL CLOB value represented by this Clob object.
long
position(Clob searchstr, long start)
Retrieves the character position at which the specified Clob object searchstr appears in this Clob object.
OutputStream
setAsciiStream(long pos)
Retrieves a stream to be used to write Ascii characters to the CLOB value that this Clob object represents, starting at position pos.
Writer
setCharacterStream(long pos)
Retrieves a stream to be used to write a stream of Unicode characters to the CLOB value that this Clob object represents, at position pos.
int
setString(long pos, String str)
Writes the given Java String to the CLOB value that this Clob object designates at the position pos.
int
setString(long pos, String str, int offset, int len)
Writes len characters of str, starting at character offset, to the CLOB value that this Clob represents.
void
truncate(long len)
Truncates the CLOB value that this Clob designates to have a length of len characters.

Method Details

getAsciiStream

public InputStream getAsciiStream()
            throws SQLException
Retrieves the CLOB value designated by this Clob object as an ascii stream.
Returns:
a java.io.InputStream object containing the CLOB data
Throws:
SQLException - if there is an error accessing the CLOB value
Since:
1.2
Usages and Demos :

View More Examples of getAsciiStream()
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:         try {
   6:             if (columnType == Types.CLOB) {
   7:         ...
   8:                 Clob clob = this.resultSet.getClob(columnIndex);
   9:                 if (clob == null)
  10:         ...
  11:                     return null;
  12:                 return clob.getAsciiStream();

View Full Code Here
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6:     private static final String CLOB_CLASS_NAME = "oracle.sql.CLOB";
   7: 
   8:         ...
   9:     public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
  10:         logger.debug("Returning Oracle CLOB as string");
  11:         Clob clob = rs.getClob(columnIndex);
  12:         ...
  13:         Clob clob = rs.getClob(columnIndex);
  14:         return (clob != null ? clob.getAsciiStream() : null);

View Full Code Here
   1: import java.io.OutputStream;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:       String newContent = null;
   6:       Clob clob = rs.getClob(9);
   7:       if (clob != null) {
   8:         ...
   9:          byte[] buf = new byte[(int)length];
  10:          clob.getAsciiStream().read(buf);
  11:          newContent = new String(buf);
  12:         ...
  13:          byte[] buf = new byte[(int)length];
  14:          clob.getAsciiStream().read(buf);

View Full Code Here
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Date;
   4:         ...
   5:     public InputStream getAsciiStream(int i) throws SQLException {
   6:         Clob clob = getClob(i);
   7:         if(null == clob) {
   8:         ...
   9:         } else {
  10:             return clob.getAsciiStream();
  11:         }

View Full Code Here
   1: import java.sql.CallableStatement;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:                 st.setLong(5, 1L);
   6:                 st.registerOutParameter(1, Types.CLOB);
   7:                 ResultSet rs = st.executeQuery();
   8:         ...
   9:                 Clob clob = st.getClob(1);
  10:                 long len = clob.length();
  11:         ...
  12:                 byte[] buf = new byte[(int)len];
  13:                 clob.getAsciiStream().read(buf);

View Full Code Here

getCharacterStream

public Reader getCharacterStream()
            throws SQLException
Retrieves 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
Since:
1.2
Usages and Demos :

View More Examples of getCharacterStream()
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Date;
   4:         ...
   5:             return (blob == null ? null :  blob.getBinaryStream());
   6:         case Types.CLOB:
   7:             return rs.getClob(index);
   8:         ...
   9:                     break;
  10:                 case Types.CLOB:
  11:                     Clob clob = (Clob) value;
  12:         ...
  13:                     stmt.setCharacterStream(index, clob.getCharacterStream(),

View Full Code Here
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:         try {
   6:             if (columnType == Types.CLOB) {
   7:         ...
   8:                 Clob clob = this.resultSet.getClob(columnIndex);
   9:                 if (clob == null)
  10:         ...
  11:                     return null;
  12:                 return clob.getCharacterStream();

View Full Code Here
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6:     private static final String CLOB_CLASS_NAME = "oracle.sql.CLOB";
   7: 
   8:         ...
   9:     public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
  10:         logger.debug("Returning Oracle CLOB as string");
  11:         Clob clob = rs.getClob(columnIndex);
  12:         ...
  13:         Clob clob = rs.getClob(columnIndex);
  14:         return (clob != null ? clob.getCharacterStream() : null);

View Full Code Here
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Date;
   4:         ...
   5:     public InputStream getAsciiStream(int i) throws SQLException {
   6:         Clob clob = getClob(i);
   7:         if(null == clob) {
   8:         ...
   9:         } else {
  10:             return clob.getCharacterStream();
  11:         }

View Full Code Here
   1: import java.sql.CallableStatement;
   2: import java.sql.Clob;
   3: import java.sql.Date;
   4:         ...
   5:         setJdbcType("char", Types.CHAR, new T_Char());
   6:         setJdbcType("clob", Types.CLOB, new T_Clob());
   7:         setJdbcType("date", Types.DATE, new T_Date());
   8:         ...
   9: 
  10:         protected static String safeClobToString(Clob aClob) throws SQLException
  11:         {
  12:         ...
  13:             char[] buf = new char[BUFSZ];
  14:             java.io.Reader stream = aClob.getCharacterStream();

View Full Code Here

getSubString

public String getSubString(long pos,
                           int length)
            throws SQLException
Retrieves 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
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
Since:
1.2
Usages and Demos :

View More Examples of getSubString(long pos,int length)
   1:                rs.next();
   2:                Clob clob = rs.getClob(1);
   3:         ...
   4:                String wholeClob = clob.getSubString(1, (int) clob.length());
   5:                return wholeClob;
   6:         ...
   7:            UIManager.setLookAndFeel(METAL_LOOK_AND_FEEL) ;
   8:            JFrame frame = new JFrame("CLOB Demo for MySQL Database. id="+id);
   9:            frame.addWindowListener(new WindowAdapter() {

View Full Code Here
   1:                rs.next();
   2:                Clob clob = rs.getClob(1);
   3:         ...
   4:                String wholeClob = clob.getSubString(1, (int) clob.length());
   5:                return wholeClob;
   6:         ...
   7:            UIManager.setLookAndFeel(METAL_LOOK_AND_FEEL) ;
   8:            JFrame frame = new JFrame("CLOB Demo for MySQL Database. id="+id);
   9:            frame.addWindowListener(new WindowAdapter() {

View Full Code Here
   1: import java.io.Serializable;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6: import oracle.sql.CLOB;
   7: 
   8:         ...
   9:         throws SQLException {
  10:         Clob clob = rs.getClob(names[0]);
  11: 
  12:         ...
  13:         return ((clob == null) ? null : clob.getSubString(1, (int) clob.length()));

View Full Code Here
   1: import java.io.Serializable;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6: import oracle.sql.CLOB;
   7: 
   8:         ...
   9:         throws SQLException {
  10:         Clob clob = rs.getClob(names[0]);
  11: 
  12:         ...
  13:         return ((clob == null) ? null : clob.getSubString(1, (int) clob.length()));

View Full Code Here
   1:             if (clobToStringConversion){
   2:                 if (x instanceof Clob){
   3:         ...
   4:                     Clob clob = (Clob)x;
   5:                     long len = clob.length();
   6:         ...
   7:               } else {
   8:               return clob.getSubString(1L, (int)len);
   9:               }

View Full Code Here

length

public long length()
            throws SQLException
Retrieves the number of characters in the CLOB value designated by this Clob object.
Returns:
length of the CLOB in characters
Throws:
SQLException - if there is an error accessing the length of the CLOB value
Since:
1.2
Usages and Demos :

View More Examples of length()
   1: 
   2:         Clob fileAsCLOB = null;
   3:         Connection conn = null;
   4:         ...
   5:         catch(Exception e) {
   6:             out.println("<html><head><title>CLOB Example</title></head>");
   7:             out.println("<body><h4>Database Connection Problem.</h4>");
   8:         ...
   9:             else {
  10:                 out.println("<html><head><title>CLOB Example</title></head>");
  11:                 out.println("<body><h4>No file found for id="+id+"</h4></body></html>");
  12:         ...
  13: 
  14:             long length = fileAsCLOB.length();

View Full Code Here
   1: 
   2:         Clob fileAsCLOB = null;
   3:         Connection conn = null;
   4:         ...
   5:         catch(Exception e) {
   6:             out.println("<html><head><title>CLOB Example</title></head>");
   7:             out.println("<body><h4>Database Connection Problem.</h4>");
   8:         ...
   9:             else {
  10:                 out.println("<html><head><title>CLOB Example</title></head>");
  11:                 out.println("<body><h3>No file found for id="+
  12:         ...
  13: 
  14:             long length = fileAsCLOB.length();

View Full Code Here
   1: 
   2:     private static final String CLOB_FILE_PREFIX = "/clob-";
   3: 
   4:         ...
   5: 
   6:     private static String getClobAsURL(Clob Clob) throws Exception {
   7: 
   8:         ...
   9:             out = new FileOutputStream(ClobFile);
  10:             int length = (int) Clob.length();

View Full Code Here
   1: import java.io.Serializable;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6: import oracle.sql.CLOB;
   7: 
   8:         ...
   9:         throws SQLException {
  10:         Clob clob = rs.getClob(names[0]);
  11: 
  12:         ...
  13:         return ((clob == null) ? null : clob.getSubString(1, (int) clob.length()));

View Full Code Here
   1: import java.io.Serializable;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5: 
   6: import oracle.sql.CLOB;
   7: 
   8:         ...
   9:         throws SQLException {
  10:         Clob clob = rs.getClob(names[0]);
  11: 
  12:         ...
  13:         return ((clob == null) ? null : clob.getSubString(1, (int) clob.length()));

View Full Code Here

position

public long position(String searchstr,
                     long start)
            throws SQLException
Retrieves 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
Since:
1.2

position

public long position(Clob searchstr,
                     long start)
            throws SQLException
Retrieves 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 object 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
Since:
1.2

setAsciiStream

public OutputStream setAsciiStream(long pos)
            throws SQLException
Retrieves 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 - if there is an error accessing the CLOB value
Since:
1.4

setCharacterStream

public Writer setCharacterStream(long pos)
            throws SQLException
Retrieves 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 - if there is an error accessing the CLOB value
Since:
1.4
Usages and Demos :

View More Examples of setCharacterStream(long pos)
   1: import java.io.Writer;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:         try {
   6:             Clob clob = (Clob)lob;
   7:             lobReader = clob.getCharacterStream();
   8:         ...
   9:             Clob clob = (Clob)lob;
  10:             lobWriter = clob.setCharacterStream(1);
  11:             int l = 0;

View Full Code Here

setString

public int setString(long pos,
                     String str)
            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 value that this Clob object represents
str - the string to be written to the CLOB value that this Clob designates
Returns:
the number of characters written
Throws:
SQLException - if there is an error accessing the CLOB value
Since:
1.4

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.
Parameters:
pos - the position at which to start writing to this CLOB object
str - the string to be written to the CLOB value that this Clob object represents
offset - the offset 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
Since:
1.4

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 bytes, to which the CLOB value should be truncated
Throws:
SQLException - if there is an error accessing the CLOB value
Since:
1.4
Usages and Demos :

View More Examples of truncate(long len)
   1: import java.io.Reader;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:             
   6:             Clob clob = this.rs.getClob(1);
   7:         ...
   8:             clob.truncate(3);
   9:             

View Full Code Here
   1: import java.sql.Blob;
   2: import java.sql.Clob;
   3: import java.sql.Connection;
   4:         ...
   5:       classOracleBLOB = Class.forName("oracle.sql.BLOB");
   6:       classOracleCLOB = Class.forName("oracle.sql.CLOB");
   7:       createTemporaryBLOB = classOracleBLOB.getDeclaredMethod("createTemporary",
   8:         ...
   9:     } catch (Exception e) {
  10:       log.log(Level.FINER, L.l("Unable to load LOB classes or methods for oracle.sql.BLOB and oracle.sql.CLOB."));
  11:     }
  12:         ...
  13:         Blob blob = (Blob) _lob;
  14:         blob.truncate(0);

View Full Code Here