Recently, the Clob field is frequently processed, so several methods of reading CLOB fields are concentrated for reference.
The first type:
Clob Clob = Rs.getclob ("remark");//java.sql.clob
Stringdetailinfo = "";
if (clob!= null) {
Detailinfo= clob.getsubstring ((Long) 1, (int) clob.length ());
}
The second type:
Clob clob= Rs.getclob ("remark");//java.sql.clob
inti = 0;
if (clob!= null) {
Inputstreaminput = Clob.getasciistream ();
Intlen = (int) clob.length ();
byteby[] = new Byte[len];
while ( -1!= (i = Input.read (by, 0, by.length))) {
Input.read (by,0, i);
}
detailinfo= new String (by, "Utf-8");
}
The third type:
Clobclob = Rs.getclob ("remark");//java.sql.clob
Stringvalue= "";
Stringline= "";
if (clob!=null) {
Reader reader= ((Oracle.sql.CLOB) CLOB). Getcharacterstream ();
BufferedReader br=new BufferedReader (reader);
while ((Line=br.readline ())!=null)
{
Value + = line + "\ r \ n";
}
}
The first method code is small, and can avoid the problem of Chinese garbled, the second method is similar to the first method of efficiency, is often used as a method, the third method is very inefficient, if the data is relatively large, it is recommended not to use.
I put 100 pages of a Word document content through FCK into a database Clob field, and then read through the above three methods, the first two methods used for almost 4 seconds, the third method used three minutes. But the first two methods do not take into account the very large data situation, generally enough (a novel is not a problem).
Several ways to read CLOB fields in Java