圖片存入ORACLE數據庫的方法

图片存入oracle 数据 库的blob字段:

//   把Image1显示的图片写入到Employee表的Photo字段  
  Query1->RequestLive   =   true;  
  Query1->SQL->Clear();  
  Query1->SQL->Add("SELECT   Photo   FROM   Employee   WHERE   Id   =   :Id");  
  Query1->Prepare();  
  Query1->Params->Items[0]->AsString   =   "0001";  
  Query1->Open();  
  Query1->Edit();  
  if   (Image1->Picture->Graphic)  
  {  
      TBlobStream   *Stream   =   new   TBlobStream(   (TBlobField   *)Query1->FieldByName("Photo"),  
                                                                                    bmReadWrite   );  
      Stream->Seek(0,   soFromBeginning);  
      try  
      {  
          Image1->Picture->Bitmap->SaveToStream(Stream);  
      }  
      __finally  
      {  
          delete   Stream;  
      }  
  }  
  else  
      ((TBlobField   *)Query1->FieldByName("Photo"))->Clear();  
  Query1->Post();  
  Query1->Close();  
  Query1->UnPrepare();  
  Query1->RequestLive   =   false;   
 

//   方法1  
  if   (!((TGraphicField   *)Query1->FieldByName("Photo"))->IsNull)  
      Image1->Picture->Assign((TGraphicField   *)Query1->FieldByName("Photo"));  
  else  
      Image1->Picture   =   NULL;  
   
   
  //   方法2  
  TBlobStream   *Stream   =   new   TBlobStream(   (TBlobField   *)Query1->FieldByName("Photo"),  
                                                                                bmRead   );  
  Stream->Seek(0,   soFromBeginning);  
  if   (Stream->Size   >   0)  
      Image1->Picture->Bitmap->LoadFromStream(Stream);  
  else  
      Image1->Picture   =   NULL;  
  delete   Stream;   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值