import java
import java
import java
public class LobPros
{
/**
* ORACLE驅動程序
*/
private static final String DRIVER =
/**
* ORACLE連接用URL
*/
private static final String URL =
/**
* 用戶名
*/
private static final String USER =
/**
* 密碼
*/
private static final String PASSWORD =
/**
* 數據庫連接
*/
private static Connection conn = null;
/**
* SQL語句對象
*/
private static Statement stmt = null;
/**
* @roseuid
*/
public LobPros()
{
}
/**
* 往數據庫中插入一個新的CLOB對象
*
* @param infile
* @throws java
* @roseuid
*/
public static void clobInsert(String infile) throws Exception
{
/* 設定不自動提交 */
boolean defaultCommit = conn
conn
try {
/* 插入一個空的CLOB對象 */
stmt
/* 查詢此CLOB對象並鎖定 */
ResultSet rs = stmt
while (rs
/* 取出此CLOB對象 */
oracle
/* 向CLOB對象中寫入數據 */
BufferedWriter out = new BufferedWriter(clob
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in
out
}
in
out
}
/* 正式提交 */
mit();
} catch (Exception ex) {
/* 出錯回滾 */
conn
throw ex;
}
/* 恢復原提交狀態 */
conn
}
/**
* 修改CLOB對象(是在原CLOB對象基礎上進行覆蓋式的修改)
*
* @param infile
* @throws java
* @roseuid
*/
public static void clobModify(String infile) throws Exception
{
/* 設定不自動提交 */
boolean defaultCommit = conn
conn
try {
/* 查詢CLOB對象並鎖定 */
ResultSet rs = stmt
while (rs
/* 獲取此CLOB對象 */
oracle
/* 進行覆蓋式修改 */
BufferedWriter out = new BufferedWriter(clob
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in
out
}
in
out
}
/* 正式提交 */
mit();
} catch (Exception ex) {
/* 出錯回滾 */
conn
throw ex;
}
/* 恢復原提交狀態 */
conn
}
/**
* 替換CLOB對象(將原CLOB對象清除
*
* @param infile
* @throws java
* @roseuid
*/
public static void clobReplace(String infile) throws Exception
{
/* 設定不自動提交 */
boolean defaultCommit = conn
conn
try {
/* 清空原CLOB對象 */
stmt
/* 查詢CLOB對象並鎖定 */
ResultSet rs = stmt
while (rs
/* 獲取此CLOB對象 */
oracle
/* 更新數據 */
BufferedWriter out = new BufferedWriter(clob
BufferedReader in = new BufferedReader(new FileReader(infile));
int c;
while ((c=in
out
}
in
out
}
/* 正式提交 */
mit();
} catch (Exception ex) {
/* 出錯回滾 */
conn
throw ex;
}
/* 恢復原提交狀態 */
conn
}
/**
* CLOB對象讀取
*
* @param outfile
* @throws java
* @roseuid
*/
public static void clobRead(String outfile) throws Exception
{
/* 設定不自動提交 */
boolean defaultCommit = conn
conn
try {
/* 查詢CLOB對象 */
ResultSet rs = stmt
while (rs
/* 獲取CLOB對象 */
oracle
/* 以字符形式輸出 */
BufferedReader in = new BufferedReader(clob
BufferedWriter out = new BufferedWriter(new FileWriter(outfile));
int c;
while ((c=in
out
}
out
in
}
} catch (Exception ex) {
conn
throw ex;
}
/* 恢復原提交狀態 */
conn
}
/**
* 向數據庫中插入一個新的BLOB對象
*
* @param infile
* @throws java
* @roseuid
*/
public static void blobInsert(String infile) throws Exception
{
/* 設定不自動提交 */
boolean defaultCommit = conn
conn
From:http://tw.wingwit.com/Article/program/Oracle/201311/18837.html