首页 > 开发 > 综合 > 正文

下载Oracle数据库中的Blob二进制文件,实例!

2024-07-21 02:23:30
字体:
来源:转载
供稿:网友
将oracle数据库中hr方案下的testfileupload表中的文件下载至系统临时目录。

void downloadfile()
??{
???oracleconnection objocon = new oracleconnection("user id=system;data source=tsems;password=system");

???oraclecommand objocmd = new oraclecommand();

???objocmd.connection = objocon;

???objocmd.commandtext = "select * from hr.testfileupload where pkid='2006'";

???filestream objfs;

???binarywriter objbw;

???int buffersize = 260;

???byte [] outbyte = new byte[buffersize];

???long retval;

???long startindex = 0;

???string filename = "";

???objocon.open();

???oracledatareader objdr = objocmd.executereader(commandbehavior.sequentialaccess);
???objdr.read();

?? filename = objdr["filename"].tostring();

???objfs = new filestream(path.gettemppath()+filename, filemode.openorcreate,fileaccess.write);

???objbw = new binarywriter(objfs);

???startindex = 0;

???retval = objdr.getbytes(8, startindex, outbyte, 0, buffersize);

???while ( retval == buffersize)
???{
????objbw.write(outbyte);

????objbw.flush();

????startindex += buffersize;

????retval = objdr.getbytes(8, startindex, outbyte, 0, buffersize);
???}

???objbw.write(outbyte, 0, (int)retval -1);

???objbw.flush();

???objbw.close();

???objfs.close();

?? bjdr.close();

???objocon.close();
??}

  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • 发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表