Java Utililty Methods SQL Clob

List of utility methods to do SQL Clob

Description

The list of methods to do SQL Clob are organized into topic(s).

Method

StringConvertClobToString(StringBuffer sb, Clob clob)
Convert Clob To String
Reader reader = clob.getCharacterStream();
char[] buffer = new char[(int) clob.length()];
while (reader.read(buffer) != -1) {
    sb.append(buffer);
return sb.toString();
StringconvertClob2String(Clob clob)
Convert a Clob into String.
if (clob != null) {
    BufferedReader in = new BufferedReader(clob.getCharacterStream());
    String line = in.readLine();
    StringBuffer result = new StringBuffer();
    while (line != null) {
        result.append(line);
        line = in.readLine();
    return result.toString();
return null;
Objectconvert(Object o, Class targetType)
convert
if (o == null) {
    return null;
Class<?> currentType = o.getClass();
if (targetType.isAssignableFrom(currentType)) {
    return o;
if (targetType == String.class) {
...
StringconvertToString(Object obj)
convert To String
String value = "";
try {
    if (obj instanceof Clob) {
        value = ((Clob) obj).getSubString(1, (int) ((Clob) obj).length());
    } else {
        value = String.valueOf(obj);
    return value;
...
StringgetClobToString(Clob clob)
get Clob To String
if (clob != null) {
    try {
        return clob.getSubString((long) 1, (int) clob.length());
    } catch (SQLException e) {
        e.printStackTrace();
return null;
...
StringgetRSClob(Object obj, String def)
get RS Clob
if (obj == null)
    return def;
if (obj instanceof java.sql.Clob)
    return ((java.sql.Clob) obj).getSubString((long) 1, (int) ((java.sql.Clob) obj).length());
System.out.println("end of getRSClob, wrong object: " + obj.getClass().getName());
return def;
StringgetFormattedClobColumn(final InputStream is)
get Formatted Clob Column
final byte b[] = new byte[BUFFER_SIZE];
final BufferedInputStream bi = new BufferedInputStream(is);
final StringBuffer sb = new StringBuffer();
try {
    while ((bi.read(b)) != -1) {
        sb.append(new String(b));
} catch (final Exception e) {
...
StringgetString(Clob c)
get String
StringBuffer s = new StringBuffer();
if (c != null) {
    try {
        BufferedReader bufferRead = new BufferedReader(c.getCharacterStream());
        try {
            String str;
            while ((str = bufferRead.readLine()) != null) {
                s.append(str);
...
StringgetStringFromClob(Clob clob)
get String From Clob
String returnValue = null;
Reader reader = null;
try {
    if (clob != null && clob.length() != 0) {
        reader = clob.getCharacterStream();
        int clobSize = (int) clob.length();
        char[] buffer = new char[clobSize];
        reader.read(buffer);
...
booleanisNClob(final Class type)
is N Clob
return java.sql.NClob.class.isAssignableFrom(type);