国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

輕松掌握jdbc操縱Oracle數(shù)據(jù)庫(kù)lob字段

瀏覽:148日期:2024-07-07 09:04:38
在Oracle數(shù)據(jù)庫(kù)中,lob(large object,大型對(duì)象)類(lèi)型的字段使用的頻率越來(lái)越高了。因?yàn)檫@種類(lèi)型的字段,容量大(最多能容納4gb的數(shù)據(jù)),且一個(gè)表中可以有多個(gè)這種類(lèi)型的字段,很靈活,適用于數(shù)據(jù)量非常大的業(yè)務(wù)領(lǐng)域(如圖象、檔案等)。而long、long raw等類(lèi)型的字段,雖然存儲(chǔ)容量也不?。蛇_(dá)2gb),但由于一個(gè)表中只能有一個(gè)這樣類(lèi)型的字段的限制,現(xiàn)在已很少使用了。lob類(lèi)型分為blob和clob兩種:blob即二進(jìn)制大型對(duì)象(binary large object),適用于存貯非文本的字節(jié)流數(shù)據(jù)(如程序、圖象、影音等)。而clob,即字符型大型對(duì)象(character largeobject),則與字符集相關(guān),適于存貯文本型的數(shù)據(jù)(如歷史檔案、大部頭著作等)。下面以程序?qū)嵗f(shuō)明通過(guò)jdbc操縱oracle數(shù)據(jù)庫(kù)lob類(lèi)型字段。先建立如下兩個(gè)測(cè)試用的數(shù)據(jù)庫(kù)表,power designer pd模型如下:建表sql語(yǔ)句為:create table test_clob ( id number(3), clobcol clob) create table test_blob ( id number(3), blobcol blob)lob對(duì)象的存取1、往數(shù)據(jù)庫(kù)中插入一個(gè)新的clob對(duì)象public static void clobinsert(string infile) throws exception { /* 設(shè)定不自動(dòng)提交 */ boolean defaultcommit = conn.getautocommit(); conn.setautocommit(false); try { /* 插入一個(gè)空的clob對(duì)象 */ stmt.executeupdate('insert into test_clob values (’111’, empty_clob())'); /* 查詢(xún)此clob對(duì)象并鎖定 */ resultset rs = stmt.executequery('select clobcol from test_clob where id=’111’ for update'); while (rs.next()) { /* 取出此clob對(duì)象 */ oracle.sql.clob clob = (oracle.sql.clob)rs.getclob('clobcol'); /* 向clob對(duì)象中寫(xiě)入數(shù)據(jù) */ bufferedwriter out = new bufferedwriter(clob.getcharacteroutputstream()); bufferedreader in = new bufferedreader(new filereader(infile)); int c; while ((c=in.read())!=-1) { out.write(c); } in.close(); out.close(); } /* 正式提交 */ conn.commit(); } catch (exception ex) { /* 出錯(cuò)回滾 */ conn.rollback(); throw ex; } /* 恢復(fù)原提交狀態(tài) */ conn.setautocommit(defaultcommit); }2、修改clob對(duì)象(是在原clob對(duì)象基礎(chǔ)上進(jìn)行覆蓋式的修改)public static void clobmodify(string infile) throws exception { /* 設(shè)定不自動(dòng)提交 */ boolean defaultcommit = conn.getautocommit(); conn.setautocommit(false); try { /* 查詢(xún)clob對(duì)象并鎖定 */ resultset rs = stmt.executequery('select clobcol from test_clob where id=’111’ for update'); while (rs.next()) { /* 獲取此clob對(duì)象 */ oracle.sql.clob clob = (oracle.sql.clob)rs.getclob('clobcol'); /* 進(jìn)行覆蓋式修改 */ bufferedwriter out = new bufferedwriter(clob.getcharacteroutputstream()); bufferedreader in = new bufferedreader(new filereader(infile)); int c; while ((c=in.read())!=-1) { out.write(c); } in.close(); out.close(); } /* 正式提交 */ conn.commit(); } catch (exception ex) { /* 出錯(cuò)回滾 */ conn.rollback(); throw ex; } /* 恢復(fù)原提交狀態(tài) */ conn.setautocommit(defaultcommit); }
標(biāo)簽: JDBC
主站蜘蛛池模板: 柯坪县| 三都| 万州区| 龙泉市| 麻城市| 启东市| 文山县| 抚顺县| 安吉县| 修文县| 新邵县| 汉川市| 桑植县| 永仁县| 文登市| 时尚| 宣恩县| 沙湾县| 西宁市| 昆山市| 涿州市| 白河县| 延津县| 崇左市| 定西市| 济阳县| 澎湖县| 锡林浩特市| 红河县| 深水埗区| 周至县| 巧家县| 宿州市| 佳木斯市| 鄄城县| 文安县| 广平县| 乌鲁木齐县| 南投县| 灯塔市| 平乐县|