Download the BLOB binary in the Oracle database, instance!

xiaoxiao2021-03-06  56

Download files in the TestFileUpload table under the Oracle database to the system temporary directory.

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.SequentialAracse); 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, Buffers);

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 ();

转载请注明原文地址:https://www.9cbs.com/read-114302.html

New Post(0)