CLOB data type

A CLOB (character large object) value can be up to 2,147,483,647 characters long. A CLOB is used to store unicode character-based data, such as large documents in any character set.

The length is given in number characters for both CLOB, unless one of the suffixes K, M, or G is given, relating to the multiples of 1024, 1024*1024, 1024*1024*1024 respectively.

Length is specified in characters (unicode) for CLOB.


{CLOB |CHARACTER LARGE OBJECT} [ ( length [{K |M |G}] ) ]


A CLOB without a specified length is defaulted to two gigabytes (2,147,483,647).

Corresponding Compile-Time Java Type


JDBC Metadata Type (java.sql.Types)


Use the getClob method on the java.sql.ResultSet to retrieve a CLOB handle to the underlying data.

Related Information

See Mapping of java.sql.Blob and java.sql.Clob interfaces.

import java.sql.*;

public class clob
	public static void main(String[] args) {
		try {
			String url = "jdbc:derby:clobberyclob;create=true";

			Connection conn = DriverManager.getConnection(url);

            Statement s = conn.createStatement();
            s.executeUpdate("CREATE TABLE documents (id INT, text CLOB(64 K))");

            // --- add a file
   file = new"asciifile.txt");
            int fileLength = (int) file.length();

            // - first, create an input stream
   fin = new;
            PreparedStatement ps = conn.prepareStatement("INSERT
            INTO documents VALUES (?, ?)");
            ps.setInt(1, 1477);

            // - set the value of the input parameter to the input stream
            ps.setAsciiStream(2, fin, fileLength);

            // --- reading the columns
            ResultSet rs = s.executeQuery("SELECT text FROM documents
             WHERE id = 1477");
            while ( {
                java.sql.Clob aclob = rs.getClob(1);
       ip = rs.getAsciiStream(1);
                int c =;
                while (c > 0) {
                    c =;
                // ...
        } catch (Exception e) {
            System.out.println("Error! "+e);