<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Java,J2EE,Weblogic,Oracle

    java項目隨筆
    隨筆 - 90, 文章 - 6, 評論 - 61, 引用 - 0
    數據加載中……

    Weblogic 下 oracle 的 blob 操作

    最后公司的WEB服務器要用 WebLogic 8.1 替換原來的 Resin ,因為要用webloic 的 數據庫連接池,原有的程序需要變動
    (1)向? blob 字段寫入值
    ???
    ?????????????????????? String medpk = dao.getElementPK(cn, vo);
    ??????????????????????????? evo.setEle_elementId(medpk);
    ??????????????????????????? evo.setEle_contentid(conpk);
    ??????????????????????????? evo.setEle_type("23");
    ??????????????????????????? dao.addElementRelation(cn, evo);
    ??????????????????????????? evo.setMmsnews_elementID(medpk);
    ?????????????????? //Connection conn=JdbcConnectionPool.getConnection();
    ??????????????????????????? try {???
    ??????????????????????????????String sql =
    "insert into OM_CM_MMSNEWS (elementid,title,content) values(?,?,empty_blob())";????????????????????????????????????? ???? ????? //1.blob字段插入空值
    ??????????????????????????????? PreparedStatement ps = cn.prepareStatement(sql);
    ?????????????????????????????????ps.setString(1, evo.getEle_elementId());
    ??????????????????????????????? ps.setString(2, evo.getMmsnews_title());
    ??????????????????????????????? ps.execute();
    ??????????????????????????????? sql =

    ??"select content from OM_CM_MMSNEWS where elementid=" + medpk +?" for update";???????????????????????????????????//2.更新指定記錄的 blob字段
    ??????????????????????????????? Statement st = cn.createStatement();
    ??????????????????????????????? ResultSet rs = st.executeQuery(sql);
    ??????????????????????????????? File file = new File(evo.getMmsnews_content());
    ??????????????????????????????? if (rs.next()) {
    ???OracleThinBlob blob = (weblogic.jdbc.vendor.oracle.OracleThinBlob) rs.getBlob(1);???????
    ????????????????????????????????????????????????????????????????//必須用weblogic 的jar包
    ??????????????????????????????????? OutputStream outStream = blob. getBinaryOutputStream();
    ??????????????????????????????????? InputStream fin = new FileInputStream(file);
    ??????????????????????????????????? byte[] b = new byte[blob.getBufferSize()];
    ??????????????????????????????????? int len = 0;
    ??????????????????????????????????? while ((len = fin.read(b)) != -1) {
    ??????????????????????????????????????? outStream.write(b, 0, len);
    ??????????????????????????????????? }
    ??????????????????????????????????? fin.close();
    ??????????????????????????????????? outStream.flush();
    ??????????????????????????????????? outStream.close();
    ??????????????????????????????? }
    ??????????????????????????????? rs.close();
    ??????????????????????????????? st.close();
    ??????????????????????????????? logger.error("this MmsNews is save!");
    ??????????????????????????? } catch (Exception ex) {
    ??????????????????????????????? logger.error(ex.getMessage());
    ??????????????????????????????? throw new Exception(ex.getMessage());
    ??????????????????????????? }



    (2)提取blob字段的值,并保存為文件
    ?private static void getZipFile(String contentid, String filepath,
    ?????????????????????????????????? String zipfile) throws
    ??????????? DOException {

    ??????? String sql = "select? content ?from om_cm_mmsnews a where a.elementid in? (select b.elementid from om_cm_elementrelation b where b.contentid in (select c.contentid from om_cm_content c where c.contentid=?))";
    ??????? Connection conn = null;
    ??????? try {
    ??????????? //建立文件夾
    ??????????? File tempDicFile = new java.io.File(filepath);
    ??????????? tempDicFile.mkdirs();

    ??????????? //提取 blob 字段的內容并保存為 zip 文件
    ??????????? conn = JdbcConnectionPool.getConnection();
    ??????????? PreparedStatement ps = conn.prepareStatement(sql);
    ??????????? ps.setString(1, contentid); //傳入 contentid
    ??????????? ResultSet rst = ps.executeQuery();
    ??????????? while (rst.next()) {
    ??????????????? /* 取出此BLOB對象 */
    ??????????????? java.sql.Blob blob = rst.getBlob("content");
    ??????????????? if (blob != null) {
    ??????????????????? /* 以二進制形式輸出 */
    ??????????????????? BufferedInputStream in = new BufferedInputStream(blob.
    ??????????????????????????? getBinaryStream());
    ??????????????????? BufferedOutputStream out = new BufferedOutputStream(new
    ??????????????????????????? FileOutputStream(zipfile));
    ??????????????????? byte[] buf = new byte[1024];
    ??????????????????? while (true)
    ??????????????????? {
    ??????????????????????? int count = in.read(buf);
    ??????????????????????? if (count <= 0)
    ??????????????????????? {
    ??????????????????????????? break;
    ??????????????????????? }
    ??????????????????????? out.write(buf, 0, count);
    ??????????????????? }
    ??????????????????? in.close();
    ??????????????????? out.close();
    ??????????????? }
    ??????????? }
    ??????????? rst.close();
    ??????????? ps.close();
    ??????????? conn.close();
    ??????????? logger.error("Mmspreview -->getZipFile 創建zip文件成功");
    ??????? } catch (Exception ex) {
    ??????????? logger.error("Mmspreview -->getZipFile 創建zip文件失敗!!!!!" +
    ???????????????????????? ex.getMessage());
    ??????? } finally {
    ??????????? PublicUtilit.rapidReleaseConnection(null, conn, null, null);
    ??????? }
    ??? }

    posted on 2006-11-16 12:39 龔椿深 閱讀(690) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲精品WWW久久久久久| 亚洲一区无码中文字幕乱码| 少妇亚洲免费精品| 亚洲一区二区三区偷拍女厕| 亚洲毛片无码专区亚洲乱| 日本系列1页亚洲系列| 欧洲精品99毛片免费高清观看| 免费无码又爽又刺激毛片| 亚洲中文字幕日产乱码高清app| 亚洲人成黄网在线观看| 中文字幕a∨在线乱码免费看| 亚洲免费福利在线视频| 在线亚洲97se亚洲综合在线| 国产99视频精品免费视频76| 韩国欧洲一级毛片免费| 国产精品久久亚洲一区二区| 亚洲一级毛片免费看| 丝袜熟女国偷自产中文字幕亚洲| 一个人免费观看www视频| 最近中文字幕mv免费高清电影| 亚洲无线观看国产精品| 西西人体免费视频| 免费女人18毛片a级毛片视频| 亚洲伦理中文字幕| 亚洲成人免费网址| 亚洲精品人成在线观看| 最近的2019免费中文字幕| 久久久无码精品亚洲日韩蜜臀浪潮| 国产精品99爱免费视频| 亚洲激情在线观看| 我要看免费的毛片| 亚洲天堂免费在线视频| 中文字幕在线观看亚洲| 99爱视频99爱在线观看免费| 国产亚洲精品VA片在线播放| 无码永久免费AV网站| 亚洲制服丝袜第一页| 亚洲色图综合在线| a毛片久久免费观看| 啊灬啊灬别停啊灬用力啊免费看| 久久九九久精品国产免费直播|