-- Take inserting an article as an example to operate the Blob field of Oracle --
The Blob field in Oracle is binary access. before uploading, convert the file to binary. Download also converts the downloaded binary data. A maximum of 4 GB of files can be accessed, which is suitable for operations on large files or non-text files. The following is a recent project that writes access to blob for your reference:
1
2 // Add an article ------------
3
4 Public void add_papers (string username, String title, string author, string author2, string author3, string text)
5 {
6
7 try
8 {
9 byte [] B = system. Text. encoding. Unicode. getbytes (text );
10
11 system. datetime time = system. datetime. now;
12 users. class1 u = new users. class1 ();
13 int uid = U. getuserid (username );
14 string SQL = "insert into paper_table (state_id, firstauthor_id, paper_name, firstwriter_name, secondwriter_name, thirdwriter_name, submit_time, paper_text )";
15 SQL = SQL + "values (: A,: B,: C,: D,: E,: F,: G,: H )";
16 oraclecommand cmd = new oraclecommand (SQL, Conn );
17
18 conn. open ();
19 cmd. Parameters. Add ("A", system. Data. oracleclient. oracletype. Number). value = 1;
20 cmd. Parameters. Add ("B", system. Data. oracleclient. oracletype. Number). value = uid;
21 cmd. Parameters. Add ("C", system. Data. oracleclient. oracletype. varchar). value = title;
22 cmd. Parameters. Add ("D", system. Data. oracleclient. oracletype. varchar). value = author;
23 cmd. Parameters. Add ("e", system. Data. oracleclient. oracletype. varchar). value = author2;
24 cmd. Parameters. Add ("F", system. Data. oracleclient. oracletype. varchar). value = author3;
25 cmd. parameters. add ("g", system. data. oracleclient. oracletype. datetime ). value = time; // "to_date ('" + time + "', 'yyyy-mm-dd hh24: MI: ss ')";
26 cmd. Parameters. Add ("H", system. Data. oracleclient. oracletype. Blob, B. Length). value = B;
27 cmd. executenonquery ();
28 conn. Close ();
29 papers. Papers P = new papers ();
30 p. insert_modified_table (title, UID );
31 P. insert_into_submit_state_table (title, UID );
32}
33 catch
34 {
35
36}
37
38}
Read text
1 // get the article content
2 Public String get_paper_text (string ID, string table)
3 {string SQL;
4 string STR = "";
5 If (Table = "paper_table ")
6 {
7 SQL = "select paper_text from paper_table where id = '" + ID + "'";
8 oraclecommand cmd = new oraclecommand (SQL, Conn );
9 conn. open ();
10 oracledatareader DR = cmd. executereader ();
11 while (dr. Read ())
12 {
13 if (Dr ["paper_text"]. tostring () = "") // if the content of the article is null, it cannot be converted to binary.
14 STR = "";
15 else
16 {
17 byte [] B = (byte []) Dr ["paper_text"];
18 STR = system. Text. encoding. Unicode. getstring (B );
19}
20}
21 conn. Close ();
22
23}