婢幣JDBC贋函寄侏方象斤?LOB秤趨議幣袈窃
扮寂:2011-02-27
婢幣JDBC贋函ORACLE寄侏方象斤?LOB叱嶽秤趨議幣袈窃
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斤? */
|