上傳檔案至Oracle資料庫

2021-03-31 08:56:29 字數 1087 閱讀 7535

在資料庫的hr方案下建立乙個名為testfileupload的表,包含3列:主鍵pkid、檔名filename、檔案file(blob型別)。

void uploadfile()

filestream objfs = new filestream(file1.value,filemode.open, fileaccess.read);

binaryreader objbr = new binaryreader(objfs);

byte bytfile = objbr.readbytes((int)objfs.length);

oracleconnection objoconn = new oracleconnection("user id=system;data source=tsems;password=system");

objoconn.open();

oracle***mand objocmd = new oracle***mand();

objocmd.connection = objoconn;

objocmd.***mandtext = "insert into hr.testfileupload values(:vpkid,:vfilename , :vfile)";

objocmd.parameters.add("vpkid", oracletype.varchar);

objocmd.parameters["vpkid"].value = "2006";

objocmd.parameters.add("vfilename",oracletype.varchar);

objocmd.parameters["vfilename"].value = path.getfilename(file1.value);

objocmd.parameters.add("vfile",oracletype.blob,bytfile.length);

objocmd.parameters["vfile"].value = bytfile;

objocmd.executenonquery();

objoconn.close();

response.write("true");

將檔案上傳到oracle資料庫的Blob欄位中

由於種種原因,需要將檔案直接儲存到oracle的blob欄位中,功能已經完成,記錄一下實現過程。採用winform實現需要的功能,首先在資料庫中建表,其中乙個欄位為blob型別,怎麼建立就不說了。思路很簡單,就是檔案流讀取電腦上的檔案,然後通過insert語句將檔案的位元組流陣列存進表中,如下 通過...

Oracle伺服器資料庫導至本地資料庫

一 開啟cmd輸入匯出語句。匯出資料庫語句 匯出後dmp檔案在伺服器上 將dmp檔案複製貼上到本地 二 建立表空間。建立使用者。create the user create user sw new local identified by 123456 default tablespace sw ne...

檔案上傳導入資料庫

strrchr查詢指定字元在字串中的最後一次出現,csv strrchr filename,查詢出.csv mb convert encoding轉換字元的編碼,從gkb轉到 if isset files file1 tmp files file1 tmp name filename files f...