clob的讀取

第一種:常用,

            Clob clob = rs.getClob("log_detail");//java.sql.Clob
             String p_text= "";
             if(clob != null){
                  detailinfo = clob.getSubString((long)1,(int)clob.length());
             }

 

 

第二種:           

    Clob clob = rs.getClob("log_detail");//java.sql.Clob
    int i = 0;
    if(clob != null){
     InputStream input = clob.getAsciiStream();
     int len = (int)clob.length();
     byte by[] = new byte[len];
     while(-1 != (i = input.read(by, 0, by.length))){
      input.read(by, 0, i);
     }
     detailinfo = new String(by, "utf-8");
    }
     

 

第三種:

String Sql="SELECT a.log_detail FROM MONITOR_B.T_SCHEDULER_JOB_LOG A WHERE A.ID=‘123456’;
ResultSet rs=MySql.HB_executeQuery(Sql);

long BlobLength; // BLOB字段長度
byte[] bytes; // BLOB臨時存儲字節數組
while(rs.next()){
        String p_text = ""; // 返回字符串
        Clob b=rs.getClob("log_detail");
        Reader is =b.getCharacterStream();
        BufferedReader br = new BufferedReader(is); 
        String s = br.readLine(); 
        StringBuffer sb = new StringBuffer(); 
        while (s != null) {// 執行循環將字符串全部取出付值給 StringBuffer由StringBuffer轉成STRING 
            sb.append(s+"\n");
            s = br.readLine(); 
        }
        p_text=sb.toString();
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章