解析jdbc處理oracle的clob字段的詳解建站知識
導讀:1建站知識本篇文章是對jdbc處理oracle的clob字段進行了詳細的分析介紹,需要的朋友參考下seo網站優化軟件網站seo優化診斷工具。
import java.io.BufferedOutputStream;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.Reader;import java.sql.Clob;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;
復制代碼 代碼如下:
public class ClobUtil { /** * * @param insertSQL 插入sql語句 有網站建設制作clob字段時,值必須設置成empty_clob()函數 例:insert into ba valus(1,empty_clob()) * @param updateSQL 帶有修改的查詢語句,并應增加條件判斷.例:select * from BA where ba_id = '"+ba.getBA_id()+"' for update * @param con 數據庫鏈接 * @param bigString 要插入的clob值 * @param updateColumn 要插入的表字段名 * @return * @throws SQLException */ public static Boolean clobInsert(String insertSQL,String updateSQL,Connection con,String bigString,String updateColumn ) t公司網站建設hrows SQLException{ // 結果集 ResultSet rs = null; // 插入數據庫的sql String query = insertSQL; // 設置不自動提交 con.setAutoCommit(false); // 定義預處理 java.sql.PreparedStatement pstmt = con.prepareStatement( query網站建設公司); // 執行插入語句 pstmt.executeUpdate(); //清空 pstmt = null; // 執行更改 query = updateSQL; //顯示執行帶有修改方式的select pstmt = con.prepareStatement(query); rs = pstmt.executeQuery(); // 采用流的方式處理結果集 if(rs.next()) { // 得到指定的clob字段 oracle.sql.CLOB singnaturedateClob = (oracle.sql.CLOB)rs.getClob(updateColumn); // 把clob字段放到輸出流當中 BufferedOutputStream out = new BufferedOutputStream(singnaturedateClob.getAsciiOutputStream()); // 判斷傳入的數據是否為空 if(bigString!=null){ try{ // 把要保存的數據轉換成輸入流 InputStream is = (InputStream)(new ByteArrayInputStream(bigString.getBytes())); copyStream( is, out ); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } rs.close(); con.commit(); return true; }
/** * 將輸入流寫入到輸出流當中 * @param is 輸入流 * @param os 輸出流 * @throws IOException */ public static void copyStream( InputStream is, OutputStream os ) throws IOException { byte[] data = new byte[4096]; int readed = is.read(data); while (readed != -1) { os.write(data,0,readed); readed = is.read(data); } } /** * 通過Clob對象返回字符串 * @param c * @return */ public static String getClobString(Clob c) { try { Reader reader=c.getCharacterStream(); if (reader == null) { return null; } StringBuffer sb = new StringBuffer(); char[] charbuf = new char[4096]; for (int i = reader.read(charbuf); i > 0; i = reader.read(charbuf)) { sb.append(charbuf, 0, i); } return sb.toString(); } catch (Exception e) { return ""; } }
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-24 ,文章解析jdbc處理oracle的clob字段的詳解建站知識主要講述字段,詳解,解析jdbc處理oracle的clob字段的詳解網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_6737.html
- 上一篇:百家號指數是什么建站知識
- 下一篇:百家號新手期轉正標準建站知識