Friday, February 26, 2010

ClobUtil

package cmhk.corpsms.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.sql.Clob;
import java.sql.SQLException;

public class ClobUtil {
public String clobToString(Clob cl) throws IOException, SQLException{
//http://www.experts-exchange.com/Programming/Languages/Java/Q_21753733.html
if (cl == null)
return "";

StringBuffer strOut = new StringBuffer();
String buff;
BufferedReader br = new BufferedReader(cl.getCharacterStream());

char[] buf = new char[256];
int n = 0;
while (-1!=(n=br.read(buf)))
{
strOut.append(buf, 0, n);
}

return strOut.toString().replaceAll("\n", "<br />");
}
}

No comments:

Post a Comment