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;
        }

    相关:

  • 相关阅读:
    服务器RAID5阵列掉了两块盘恢复数据过程
    sql server数据库错误数据恢复过程
    raid崩溃导致存储虚拟化平台数据丢失
    详解MBR分区结构以及GPT分区结构
    存储硬件故障如何恢复数据库
    服务器raid常见故障解决方案
    误删除VMware虚拟机vmdk文件的恢复方法
    HP P2000 服务器数据恢复+服务器数据恢复通用办法
    DELL EqualLogic PS6100存储数据丢失的解决方案
    IBM DS4800服务器RAID信息丢失数据恢复方法
  • 原文地址:https://www.cnblogs.com/ding0910/p/1756324.html
Copyright © 2011-2022 走看看