<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    小石頭
    Excellence in any department can be attained only by the labor of a lifetime; it is not to be purchased at a lesser price.
    posts - 91,comments - 22,trackbacks - 0
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    ??
    public class LobPros
    {
    ??
    ? ? /**
    ? ???* ORACLE驅動程序
    ? ???*/
    ? ? private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
    ??
    ? ? /**
    ? ???* ORACLE連接用URL
    ? ???*/
    ? ? private static final String URL = "jdbc:oracle:thin:@test2000:1521:orac";
    ??
    ? ? /**
    ? ???* 用戶名
    ? ???*/
    ? ? private static final String USER = "user";
    ??
    ? ? /**
    ? ???* 密碼
    ? ???*/
    ? ? private static final String PASSWORD = "pswd";
    ??
    ? ? /**
    ? ???* 數據庫連接
    ? ???*/
    ? ? private static Connection conn = null;
    ??
    ? ? /**
    ? ???* SQL語句對象
    ? ???*/
    ? ? private static Statement stmt = null;
    ??
    ? ? /**
    ? ???* @roseuid 3EDA089E02BC
    ? ???*/
    ? ? public LobPros()
    ? ? {
    ??
    ? ? }
    ??
    ? ? /**
    ? ???* 往數據庫中插入一個新的CLOB對象
    ? ???*
    ? ???* @param infile - 數據文件
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA04A902BC
    ? ???*/
    ? ? public static void clobInsert(String infile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 插入一個空的CLOB對象 */
    ? ?? ?? ?? ?stmt.executeUpdate("INSERT INTO TEST_CLOB VALUES ('111', EMPTY_CLOB())");
    ? ?? ?? ?? ?/* 查詢此CLOB對象并鎖定 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 取出此CLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
    ? ?? ?? ?? ?? ? /* 向CLOB對象中寫入數據 */
    ? ?? ?? ?? ?? ? 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) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* 修改CLOB對象(是在原CLOB對象基礎上進行覆蓋式的修改)
    ? ???*
    ? ???* @param infile - 數據文件
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA04B60367
    ? ???*/
    ? ? public static void clobModify(String infile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 查詢CLOB對象并鎖定 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 獲取此CLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");? ?
    ? ?? ?? ?? ?? ? /* 進行覆蓋式修改 */
    ? ?? ?? ?? ?? ? 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) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* 替換CLOB對象(將原CLOB對象清除,換成一個全新的CLOB對象)
    ? ???*
    ? ???* @param infile - 數據文件
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA04BF01E1
    ? ???*/
    ? ? public static void clobReplace(String infile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 清空原CLOB對象 */
    ? ?? ?? ?? ?stmt.executeUpdate("UPDATE TEST_CLOB SET CLOBCOL=EMPTY_CLOB() WHERE ID='111'");
    ? ?? ?? ?? ?/* 查詢CLOB對象并鎖定 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT CLOBCOL FROM TEST_CLOB WHERE ID='111' FOR UPDATE");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 獲取此CLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
    ? ?? ?? ?? ?? ? /* 更新數據 */
    ? ?? ?? ?? ?? ? 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) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* CLOB對象讀取
    ? ???*
    ? ???* @param outfile - 輸出文件名
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA04D80116
    ? ???*/
    ? ? public static void clobRead(String outfile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 查詢CLOB對象 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT * FROM TEST_CLOB WHERE ID='111'");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 獲取CLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("CLOBCOL");
    ? ?? ?? ?? ?? ? /* 以字符形式輸出 */
    ? ?? ?? ?? ?? ? BufferedReader in = new BufferedReader(clob.getCharacterStream());
    ? ?? ?? ?? ?? ? BufferedWriter out = new BufferedWriter(new FileWriter(outfile));
    ? ?? ?? ?? ?? ? int c;
    ? ?? ?? ?? ?? ? while ((c=in.read())!=-1) {
    ? ?? ?? ?? ?? ?? ???out.write(c);
    ? ?? ?? ?? ?? ? }
    ? ?? ?? ?? ?? ? out.close();
    ? ?? ?? ?? ?? ? in.close();
    ? ?? ?? ?? ?}
    ? ?? ???} catch (Exception ex) {
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* 向數據庫中插入一個新的BLOB對象
    ? ???*
    ? ???* @param infile - 數據文件
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA04E300F6
    ? ???*/
    ? ? public static void blobInsert(String infile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 插入一個空的BLOB對象 */
    ? ?? ?? ?? ?stmt.executeUpdate("INSERT INTO TEST_BLOB VALUES ('222', EMPTY_BLOB())");
    ? ?? ?? ?? ?/* 查詢此BLOB對象并鎖定 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 取出此BLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");
    ? ?? ?? ?? ?? ? /* 向BLOB對象中寫入數據 */
    ? ?? ?? ?? ?? ? BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());
    ? ?? ?? ?? ?? ? BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));
    ? ?? ?? ?? ?? ? int c;
    ? ?? ?? ?? ?? ? while ((c=in.read())!=-1) {
    ? ?? ?? ?? ?? ?? ???out.write(c);
    ? ?? ?? ?? ?? ? }
    ? ?? ?? ?? ?? ? in.close();
    ? ?? ?? ?? ?? ? out.close();
    ? ?? ?? ?? ?}
    ? ?? ?? ?? ?/* 正式提交 */
    ? ?? ?? ?? ?conn.commit();
    ? ?? ???} catch (Exception ex) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* 修改BLOB對象(是在原BLOB對象基礎上進行覆蓋式的修改)
    ? ???*
    ? ???* @param infile - 數據文件
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA04E90106
    ? ???*/
    ? ? public static void blobModify(String infile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 查詢BLOB對象并鎖定 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 取出此BLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");
    ? ?? ?? ?? ?? ? /* 向BLOB對象中寫入數據 */
    ? ?? ?? ?? ?? ? BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());
    ? ?? ?? ?? ?? ? BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));
    ? ?? ?? ?? ?? ? int c;
    ? ?? ?? ?? ?? ? while ((c=in.read())!=-1) {
    ? ?? ?? ?? ?? ?? ???out.write(c);
    ? ?? ?? ?? ?? ? }
    ? ?? ?? ?? ?? ? in.close();
    ? ?? ?? ?? ?? ? out.close();
    ? ?? ?? ?? ?}
    ? ?? ?? ?? ?/* 正式提交 */
    ? ?? ?? ?? ?conn.commit();
    ? ?? ???} catch (Exception ex) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* 替換BLOB對象(將原BLOB對象清除,換成一個全新的BLOB對象)
    ? ???*
    ? ???* @param infile - 數據文件
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA0505000C
    ? ???*/
    ? ? public static void blobReplace(String infile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 清空原BLOB對象 */
    ? ?? ?? ?? ?stmt.executeUpdate("UPDATE TEST_BLOB SET BLOBCOL=EMPTY_BLOB() WHERE ID='222'");
    ? ?? ?? ?? ?/* 查詢此BLOB對象并鎖定 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 取出此BLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");
    ? ?? ?? ?? ?? ? /* 向BLOB對象中寫入數據 */
    ? ?? ?? ?? ?? ? BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());
    ? ?? ?? ?? ?? ? BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));
    ? ?? ?? ?? ?? ? int c;
    ? ?? ?? ?? ?? ? while ((c=in.read())!=-1) {
    ? ?? ?? ?? ?? ?? ???out.write(c);
    ? ?? ?? ?? ?? ? }
    ? ?? ?? ?? ?? ? in.close();
    ? ?? ?? ?? ?? ? out.close();
    ? ?? ?? ?? ?}
    ? ?? ?? ?? ?/* 正式提交 */
    ? ?? ?? ?? ?conn.commit();
    ? ?? ???} catch (Exception ex) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* BLOB對象讀取
    ? ???*
    ? ???* @param outfile - 輸出文件名
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA050B003B
    ? ???*/
    ? ? public static void blobRead(String outfile) throws Exception
    ? ? {
    ? ?? ???/* 設定不自動提交 */
    ? ?? ???boolean defaultCommit = conn.getAutoCommit();
    ? ?? ???conn.setAutoCommit(false);
    ??
    ? ?? ???try {
    ? ?? ?? ?? ?/* 查詢BLOB對象 */
    ? ?? ?? ?? ?ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222'");
    ? ?? ?? ?? ?while (rs.next()) {
    ? ?? ?? ?? ?? ? /* 取出此BLOB對象 */
    ? ?? ?? ?? ?? ? oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");
    ? ?? ?? ?? ?? ? /* 以二進制形式輸出 */
    ? ?? ?? ?? ?? ? BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outfile));
    ? ?? ?? ?? ?? ? BufferedInputStream in = new BufferedInputStream(blob.getBinaryStream());
    ? ?? ?? ?? ?? ? int c;
    ? ?? ?? ?? ?? ? while ((c=in.read())!=-1) {
    ? ?? ?? ?? ?? ?? ???out.write(c);
    ? ?? ?? ?? ?? ? }
    ? ?? ?? ?? ?? ? in.close();
    ? ?? ?? ?? ?? ? out.close();
    ? ?? ?? ?? ?}
    ? ?? ?? ?? ?/* 正式提交 */
    ? ?? ?? ?? ?conn.commit();
    ? ?? ???} catch (Exception ex) {
    ? ?? ?? ?? ?/* 出錯回滾 */
    ? ?? ?? ?? ?conn.rollback();
    ? ?? ?? ?? ?throw ex;
    ? ?? ???}
    ??
    ? ?? ???/* 恢復原提交狀態 */
    ? ?? ???conn.setAutoCommit(defaultCommit);
    ? ? }
    ??
    ? ? /**
    ? ???* 建立測試用表格
    ? ???* @throws Exception
    ? ???*/
    ? ? public static void createTables() throws Exception {
    ? ?? ???try {
    ? ?? ?? ?? ?stmt.executeUpdate("CREATE TABLE TEST_CLOB ( ID NUMBER(3), CLOBCOL CLOB)");
    ? ?? ?? ?? ?stmt.executeUpdate("CREATE TABLE TEST_BLOB ( ID NUMBER(3), BLOBCOL BLOB)");
    ? ?? ???} catch (Exception ex) {
    ??
    ? ?? ???}
    ? ? }
    ??
    ? ? /**
    ? ???* @param args - 命令行參數
    ? ???* @throws java.lang.Exception
    ? ???* @roseuid 3EDA052002AC
    ? ???*/
    ? ? public static void main(String[] args) throws Exception
    ? ? {
    ? ?? ???/* 裝載驅動,建立數據庫連接 */
    ? ?? ???Class.forName(DRIVER);
    ? ?? ???conn = DriverManager.getConnection(URL,USER,PASSWORD);
    ? ?? ???stmt = conn.createStatement();
    ??
    ? ?? ???/* 建立測試表格 */
    ? ?? ???createTables();
    ??
    ? ?? ???/* CLOB對象插入測試 */
    ? ?? ???clobInsert("c:/clobInsert.txt");
    ? ?? ???clobRead("c:/clobInsert.out");
    ??
    ? ?? ???/* CLOB對象修改測試 */
    ? ?? ???clobModify("c:/clobModify.txt");
    ? ?? ???clobRead("c:/clobModify.out");
    ??
    ? ?? ???/* CLOB對象替換測試 */
    ? ?? ???clobReplace("c:/clobReplace.txt");
    ? ?? ???clobRead("c:/clobReplace.out");
    ??
    ? ?? ???/* BLOB對象插入測試 */
    ? ?? ???blobInsert("c:/blobInsert.doc");
    ? ?? ???blobRead("c:/blobInsert.out");
    ??
    ? ?? ???/* BLOB對象修改測試 */
    ? ?? ???blobModify("c:/blobModify.doc");
    ? ?? ???blobRead("c:/blobModify.out");
    ??
    ? ?? ???/* BLOB對象替換測試 */
    ? ?? ???blobReplace("c:/blobReplace.doc");
    ? ?? ???blobRead("c:/bolbReplace.out");
    ??
    ? ?? ???/* 關閉資源退出 */
    ? ?? ???conn.close();
    ? ?? ???System.exit(0);
    ? ? }
    }
    posted on 2007-02-12 20:12 小石頭 閱讀(188) 評論(0)  編輯  收藏 所屬分類: 每天學一點
    主站蜘蛛池模板: 国产精品美女久久久免费| 亚洲国产视频网站| 日韩精品亚洲专区在线影视| 亚洲电影免费观看| 亚洲一区二区三区影院 | 无码天堂亚洲国产AV| 91青青青国产在观免费影视| 四虎永久在线精品免费影视| 亚洲精品午夜国产va久久| 成人妇女免费播放久久久| 日本免费v片一二三区| 亚洲一区二区三区四区视频| 污污网站18禁在线永久免费观看| 免费在线观看黄色毛片| 亚洲制服丝袜在线播放| 亚洲w码欧洲s码免费| 亚洲 小说区 图片区 都市| 亚洲美女视频免费| 黄页网址大全免费观看12网站| 免费99精品国产自在现线| 亚洲va在线va天堂va不卡下载| 中文字幕在线观看免费| 亚洲伦乱亚洲h视频| 曰批全过程免费视频免费看| 国内外成人免费视频| 亚洲精品一二三区| 思思99re66在线精品免费观看| 亚洲视频国产精品| 亚洲成人免费网址| 日产亚洲一区二区三区| 在线播放免费人成视频网站| 成年女人午夜毛片免费视频| 亚洲人成77777在线观看网| 美女视频黄a视频全免费| 亚洲另类春色校园小说| 在线观看特色大片免费视频 | 免费又黄又爽的视频| 又黄又大的激情视频在线观看免费视频社区在线 | 亚洲福利一区二区精品秒拍| 免费精品无码AV片在线观看| 国产亚洲美女精品久久久久狼|