2015.1.5 Write, read binary fields with Dbfactorysingleton and Oralce clob type fields read and write [unless internal parsing is required, do not use clob,clob speed more than 15 times times slower than blobs]

Source: Internet
Author: User

Write

FileStream fstr = File.openread (Tb_filepath. Text); The OpenRead function is used to open a read-only file, Openwrite writable

BinaryReader br = new BinaryReader (FSTR);

byte[] buffer = br. Readbytes ((int) fstr. Length);

String sql = string. Format ("INSERT into Nvduser_flt. File_source values (+, ', ',: cont, ' we ') ");

IDbConnection cnn = Dbfactorysingleton.getinstance (). Factory.getconnection ();

Cnn. Open ();

IDbCommand dbcom = Dbfactorysingleton.getinstance (). Factory.getcommand ();

Dbcom. Connection = CNN;

Dbcom.commandtext = SQL;

System.Data.IDataParameter mypara= dbfactorysingleton.getinstance (). Factory.getdataparameter ("cont", dbtype.binary);

Mypara. Value = buffer;

Dbcom. Parameters.Add (Mypara);

Dbcom. ExecuteNonQuery ();

Fstr. Close ();

Read

String sql = string. Format ("Select content from {0}.file_source where file_id={1}", Aislogical.dbuser,fid);

byte[] data = (byte[]) dbfactorysingleton.getinstance (). Factory.executescalar (SQL);

if (data! = NULL)

{

String EP = Application.executablepath;

EP = EP. Substring (0, Ep. LastIndexOf ("\ \") + 1);

Try

{

string[] FLs = Directory.GetFiles (EP, "Tmpsourcefile.*");

foreach (String fl in FLs)

File.delete (FL);

}

Catch {}

Try

{

String pf = EP + "Tmpsourcefile." +HZM;

FileStream stream = new FileStream (PF, filemode.createnew, FileAccess.Write);

BinaryWriter bw = new BinaryWriter (stream);

Bw. Write (data);

Bw. Close ();

Stream. Close ();

Thread.Sleep (100);

Process proc = new process ();

Proc. Startinfo.filename = PF;

Proc. Startinfo.arguments = "";

Proc. Start ();

}

Catch {}

}

CLOB, Blob is Oracle two special field type size limit are 4g,clob and blob is the difference is CLOB processing large string, and Blob is quite a sophomore binary file. Clob is similar to string comparisons in Oracle internal Dbms_lob, and is not described here.

Insert:

OracleParameter para = new OracleParameter ("cont", Oracletype.clob);

Para. Value = Xmlheader;

Cmd. Parameters.clear ();

Cmd. Parameters.Add (para);

Cmd.commandtext = "INSERT into Kmlview (name,content) VALUES (' Airport ',: cont)";

Cmd. ExecuteNonQuery ();

READ: No difference from reading a normal string

sql = string. Format ("Select content from {0}.kmlview where name= ' airport '", Aislogical.dbuser);

String data = Dbfactorysingleton.getinstance (). Factory.executescalar (SQL). ToString (). Trim ();

unless internal parsing is required, do not use CLOB , CLOB faster than BLOB Slow Speed the times more than

2015.1.5 Write, read binary fields with Dbfactorysingleton and Oralce clob type fields read and write [unless internal parsing is required, do not use clob,clob speed 15 times times slower than blobs]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.