oracle 查詢數據

今天在ORACLE數據庫中查找數據,碰到了一個表中有個字符類型爲CHAR[2000],由於字符長,用String無法取出。經過google 百度之後發現可以用CLOB類型來取。具體方法跟用字符串的方法差不多,只不過最後需要將CLOB類型轉換成字符串類型。關鍵代碼如下:    

CLOB fztdjqs = null;
     PrintWriter fztdjqsOut=response.getWriter();
  try {
   s = myConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
     ResultSet.CONCUR_READ_ONLY);
   r = s.executeQuery("SELECT * FROM TAB_FZTDJQS where xzcbm="+bianMa);
        
    while (r.next()) {
     fztdjqs=(CLOB) r.getClob("FZTD");
     System.out.println(fztdjqs.toString());
    }
   
  } catch (SQLException e) {
   e.printStackTrace();
  }

 public String ClobToString(CLOB clob) throws SQLException, IOException {    
 String reString = "";  
 Reader is = clob.getCharacterStream();// 得到流   
 BufferedReader br = new BufferedReader(is);  
 String s = br.readLine();  
 StringBuffer sb = new StringBuffer();  
 while (s != null) {// 執行循環將字符串全部取出付值給StringBuffer由StringBuffer轉成STRING   
 sb.append(s);  
 s = br.readLine();  
 }  
 reString = sb.toString();  
 return reString;  
 }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章