zoukankan      html  css  js  c++  java
  • java读写oracle Blob数据

    代码
    public int setBlob(DBConnection dbConn, String table, String idField, String fieldName, 
                String id, String content, 
    boolean bApeand) {
            
    int ret = -1;
            PreparedStatement pstmt 
    = null;
            ResultSet rs 
    = null;
            
    try {
                content 
    = this.preDisposeString(content);
                
    //java.sql.*
                Connection conn = dbConn.getConnection();
                String sql 
    = "select "+fieldName+" from "+table+" where "+idField+"="+id+" for update";
                pstmt 
    = conn.prepareStatement(sql);
                rs 
    = pstmt.executeQuery();
                Blob blob 
    = null;
                
    if (rs.next()) {
                    
    //获取blob对象,此处的blob是oracle.sql.Blob   
                    blob = (Blob)rs.getBlob(fieldName);
                    
    //执行更新操作   
                    long pos = 0//Blob.length();
                    if(bApeand) {
                        pos 
    = blob.length() + 8;
                        
    if(blob.length() > 0) {
                            content 
    = " \n " + content;
                        }
                    }
                     OutputStream wr 
    = ((BLOB)blob).getBinaryOutputStream();
                     InputStream param 
    = (InputStream) (new ByteArrayInputStream(content.getBytes()));
                     
    for(int temp = param.read(); temp != -1; temp = param.read()) {
                         wr.write(temp);
                     }

                     wr.flush();
                     wr.close();
    //                //
                    ret = 1;
                }
            } 
    catch(SQLException es) {
                es.printStackTrace();
                ret 
    = -1;
            } 
    catch(Exception e) {
                e.printStackTrace();
                ret 
    = -1;
            } 
    finally {
                
    try {
                    
    if(null != rs) {
                        rs.close();
                    }
                    
    if(null != pstmt) {
                        pstmt.close();
                    }
                } 
    catch (SQLException e) {}
            }
            
    return ret;
        }

    相关:

  • 相关阅读:
    cocos2dx源码分析之二:引擎的内存管理
    cocos2dx源码分析之一:大体运行流程
    对语言、层次和虚拟机的简单理解
    cocos2dx lua中异步加载网络图片,可用于显示微信头像
    对于c语言存储分配程序(malloc函数)实现的理解
    内存对齐的理解
    C和C++中#define的使用方法
    Unix系统中对于文件权限信息的本质理解
    npm 安装相关环境及测试
    Win7 之 NodeJS 安装
  • 原文地址:https://www.cnblogs.com/ding0910/p/1756324.html
Copyright © 2011-2022 走看看