首页 > 数据库 > Oracle > 正文

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

2024-08-29 13:35:36
字体:
来源:转载
供稿:网友

  将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();
??}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表