oracle 中 blob类型数据修改(从file保存到数据库,从java.sql.Blob 保存到oracle.sql.BLOB )

参考文章:

http://blog.csdn.net/gdweijin/article/details/5958277  


import java.lang.reflect.Proxy;
import org.hibernate.engine.jdbc.SerializableBlobProxy;
import  java.sql.Blob;



Blob stepBlobSmall;
Blob stepBlobBig;
File imageSmall;
File imageBig;
public void updatePic(Integer id,File imageSmall,File imageBig,Blob stepBlobSmall,Blob stepBlobBig)
	{		
		//imageSmall||stepBlobSmall    imageBig||stepBlobBig
		
		PreparedStatement pstmt=null;
		try {
		String sql ="UPDATE STANDARD_BOOK SB SET SB.IMAGE_SMALL =?,SB.IMAGE_BIG = ? WHERE SB.ID="+id;
		
		
		 Connection conn = this.getSession().connection();
		 
	     pstmt = conn.prepareStatement(sql);
		System.out.println(stepBlobSmall);
		


		
		
		  if (imageSmall!=null) {
		   FileInputStream fis;
			fis = new FileInputStream(imageSmall);
		   pstmt.setBinaryStream(1, fis, fis.available()); 
		  }else if(stepBlobSmall!=null){
			  SerializableBlobProxy proxy = (SerializableBlobProxy )Proxy.getInvocationHandler(stepBlobSmall);   
				java.sql.Blob stepBlobSmallBLOB = proxy.getWrappedBlob();  
			  pstmt.setBlob(1, stepBlobSmallBLOB);
		  }else {
			  pstmt.setBinaryStream(1,null,0); 
		  }
		  if (imageBig!=null) {
			   FileInputStream fis;
				fis = new FileInputStream(imageBig);
			   pstmt.setBinaryStream(2, fis, fis.available()); 
			  }else if(stepBlobBig!=null){
				  SerializableBlobProxy proxy = (SerializableBlobProxy )Proxy.getInvocationHandler(stepBlobBig);   
					java.sql.Blob stepBlobBigBLOB = proxy.getWrappedBlob();  
				  pstmt.setBlob(2, stepBlobBigBLOB); 
			  }else{
				  pstmt.setBinaryStream(2,null,0); 
			  }
		
		     pstmt.executeUpdate();   
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			try
			{
				
				pstmt.close();
			
				pstmt = null;
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
	}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值