oracle 操作lob檔案(舉例Blob)

2021-08-31 21:57:00 字數 1704 閱讀 4109

一.寫入blob

1.先在blob中插入empty_blob()

2.獲得對剛剛插入記錄的引用

blob blob = (blob) rs.getblob("你的blob欄位名稱");

3.寫入

outputstream out = blob.getbinaryoutputstream();

out.write(encypwd);//注意這裡

二.讀出blob

1.blob = rs.getblob("你的blob欄位名稱");

、2.inputstream is = blob.getbinarystream();

int length = (int) blob.length();

byte buffer = new byte[length];

is.read(buffer);

is.close();

3.你有了is就隨便處理了

比如說輸出到乙個檔案

fileoutputstream fo = new fileoutputstream(filename);//資料到的檔名

fo.write(buffer);

fo.close();

一、blob操作

1、入庫

(1)jdbc方式

//通過jdbc獲得資料庫連線

class.forname("oracle.jdbc.driver.oracledriver");

connection con = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:testdb", "test", "test");

con.setautocommit(false);

statement st = con.createstatement();

//插入乙個空物件empty_blob()

st.executeupdate("insert into testblob (id, name, blobattr) values (1, "thename", empty_blob())");

//鎖定資料行進行更新,注意「for update」語句

resultset rs = st.executequery("select blobattr from testblob where id=1 for update");

if (rs.next())

outstream.flush();

outstream.close();

con.commit();

con.close();

2、出庫

//獲得資料庫連線

connection con = connectionfactory.getconnection();

con.setautocommit(false);

statement st = con.createstatement();

//不需要「for update」

resultset rs = st.executequery("select blobattr from testblob where id=1");

if (rs.next())

instream.close();

con.commit();

con.close();

oracle 操作lob檔案(舉例Blob)

一.寫入blob 1.先在blob中插入empty blob 2.獲得對剛剛插入記錄的引用 blob blob blob rs.getblob 你的blob欄位名稱 3.寫入 outputstream out blob.getbinaryoutputstream out.write encypwd ...

Oracle如何操作LOB

dbms lob create table lob table key value integer,b lob blob,c lob clob,n lob nclob,f lob bfile insert into a table values empty blob insert into lob ...

oracle中lob型別的相關操作

在oracle的早期版本中,使用long 和long raw型別存放大資料。從8i版本開始,oracle引入了lob資料型別,並且oracle建議開發人員盡量去使用lob型別而不去使用 long 和long raw定位器 是操作這些值的指標。當我們想讀取或者修改lob資料時,我們必須先要獲取lob ...