/*
     * 将对象转化成java.sql.Blob 
     * 要求 对象是序列化的
     
*/
    
public  java.sql.Blob ObjectToBlob(Object obj)  throws  IOException{
        
try  {
            ByteArrayOutputStream out 
=   new  ByteArrayOutputStream();
            ObjectOutputStream outputStream 
=   new  ObjectOutputStream(out);
            outputStream.writeObject(obj);
            
byte [] bytes  =  out.toByteArray();
            outputStream.close();
            
return  Hibernate.createBlob(bytes);
        } 
catch  (Exception e) {
            
//  TODO: handle exception
            System.out.println( " ObjectToBlob " );
            
return   null ;
        }        
    }
    
    
    
/*
     * 将java.sql.Blob 转化成 对象 相应对象
     * 要求 对象是序列化的
     
*/     
    
public  Object BlobToObject(java.sql.Blob desblob,Object obj)  throws  IOException{
        
try  {
            ObjectInputStream in 
=   new  ObjectInputStream(desblob.getBinaryStream());
            obj 
=   in.readObject();
            in.close();    
            
return  obj;
        } 
catch  (Exception e) {
            
//  TODO: handle exception
            System.out.println( " BlobToObject " );
            e.printStackTrace();
            
return   null ;
        }        
    }    

相关文章:

  • 2021-08-28
  • 2021-07-19
  • 2021-07-19
  • 2022-12-23
  • 2021-06-17
猜你喜欢
  • 2021-11-16
  • 2021-06-25
  • 2021-08-22
  • 2021-06-18
  • 2021-06-29
相关资源
相似解决方案