Clob to String

Posted: 24th May 2011 by Jak in Database, Java, Oracle
Tags: , ,

Para convertir un dato tipo clob a otro tipo string en java se pueden usar varias formas:

1.- La mas simple:

rs.getClob("campo").getSubString(1,(int)rs.getClob("campo").length());

2.- Con un metodo:

public static String clobStringConversion(Clob clb) throws IOException, SQLException {
  if (clb == null) return ""; 
  StringBuffer str = new StringBuffer();
  String strng; 
  BufferedReader bufferRead = new BufferedReader(clb.getCharacterStream());
  while ((strng=bufferRead .readLine())!=null)
     str.append(strng);
  bufferRead.close();
  return str.toString(); 
}
Share