Writing Oracle clob and BLOB fields simultaneously

Source: Internet
Author: User
Tags oracleconnection

Some data is used for testing, but I think the function is basically implemented. The method for inserting clob or blob is also attached. I also made some modifications on it.

Which can insert both clob and blob
1 /**/ ///   <Summary>
2 /// Write both clob and blob
3 ///   </Summary>
4 ///   <Param name = "BT"> Blob field storage value </Param>
5 ///   <Param name = "clobbt"> Value stored in the clob Field </Param>
6 ///   <Returns> </returns>
7 Private   Bool Insertbloborclob ( Byte [] BT, Byte [] Clobbt)
8 {
9 Oracleconnection connection =   New Oracleconnection (constr );
10 Connection. open ();
11 Oracletransaction transaction = Connection. begintransaction ();
12 Oraclecommand command = Connection. createcommand ();
13 Command. Transaction = Transaction;
14 Command. commandtext =   " Declare XX blob; YY clob; begin dbms_lob.createtemporary (XX, false, 0); dbms_lob.createtemporary (YY, false, 0);: tempblob: = xx;: tempclob: = YY; end; " ;
15 Command. Parameters. Add ( New Oracleparameter ( " Tempblob " , Oracletype. Blob). Direction = Parameterdirection. output;
16 Command. Parameters. Add ( New Oracleparameter ( " Tempclob " , Oracletype. clob). Direction = Parameterdirection. output;
17 Command. executenonquery ();
18
19 Oraclelob templob = (Oraclelob) command. Parameters [ 0 ]. Value;
20 Byte [] Tempbuff = Bt;
21 Templob. beginbatch (oraclelobopenmode. readwrite );
22 Templob. Write (tempbuff, 0 , Tempbuff. Length );
23 Templob. endbatch ();
24 Oraclelob templob2 = (Oraclelob) command. Parameters [ 1 ]. Value;
25 Byte [] Tempbuff2 = Clobbt;
26 Templob2.beginbatch (oraclelobopenmode. readwrite );
27 Templob2.write (tempbuff2, 0 , Tempbuff2.length );
28 Templob2.endbatch ();
29 Command. Parameters. Clear ();
30 Command. commandtext =   " Insert into blobclob (Case No., body, content) values ('caseno',: importcoc,: importdoc) " ;
31 Command. commandtype = Commandtype. text;
32
33 Command. Parameters. Add ( New Oracleparameter ( " Importdoc " , Oracletype. Blob). Value = Templob;
34 Command. Parameters. Add ( New Oracleparameter ( " Importcoc " , Oracletype. clob). Value = Templob2;
35 Int Num = Command. executenonquery ();
36 Transaction. Commit ();
37 Connection. Close ();
38 Return (Num > = 1 );
39 }

Separately inserted

Separately inserted
1 Oracleconnection connection =   New Oracleconnection ( " Server = myserver; Integrated Security = yes; " );
2 Connection. open ();
3 Oracletransaction transaction = Connection. begintransaction ();
4 Oraclecommand command = Connection. createcommand ();
5 Command. Transaction = Transaction;
6 Command. commandtext =   " Declare XX blob; begin dbms_lob.createtemporary (XX, false, 0);: tempblob: = xx; end; " ;
7 Command. Parameters. Add ( New Oracleparameter ( " Tempblob " , Oracletype. Blob). Direction = Parameterdirection. output;
8 Command. executenonquery ();
9 Oraclelob templob = (Oraclelob) command. Parameters [ 0 ]. Value;
10 Byte [] Tempbuff =   New   Byte [ 10000 ];
11 Templob. beginbatch (oraclelobopenmode. readwrite );
12 Templob. Write (tempbuff, 0 , Tempbuff. Length );
13 Templob. endbatch ();
14 Command. Parameters. Clear ();
15 Command. commandtext =   " Mytable. myproc " ;
16 Command. commandtype = Commandtype. storedprocedure;
17 Command. Parameters. Add ( New Oracleparameter ( " Importdoc " , Oracletype. Blob). Value = Templob;
18 Command. executenonquery ();
19 Transaction. Commit ();

Make a record for yourself.

Related Article

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.