blob이나 clob이나 마찬가지이구요 insert나 update나 똑같이 적용됩니다.
... 중간생략
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int result = 0;
StringBuffer strSQL = new StringBuffer();
StringBuffer strSQL = new StringBuffer();
strSQL.append("UPDATE DVMSCONTRACTH \n");
strSQL.append("SET const_st = ?, \n");
strSQL.append(" contents = empty_clob(), \n");
strSQL.append("WHERE cont_no = ? \n");
strSQL.append("AND add_cont_no = ? ");
//CLOB column의 "NULL" value 방지
con.setAutoCommit(false);
try {
con = getConnection(ORACLE_DRIVER);
pstmt = con.prepareStatement(strSQL.toString());
pstmt.setString(1, "70");
pstmt.setString(2, cont_no);
pstmt.setInt(3, int_cont_no2);
result = pstmt.executeUpdate();
} catch (SQLException se) {
throw se;
} finally {
pstmt.close();
}
if(result > 0) {
//위에서 INSERT or UPDATE한 데이터를 다시 가져옵니다.
StringBuffer clobSQL = new StringBuffer();
clobSQL.append("SELECT contents FROM DVMSCONTRACTH \n");
clobSQL.append("WHERE cont_no = ? \n");
clobSQL.append("AND add_cont_no = ? ");
try {
ps = conn.prepareStatement(clobSQL.toString());
pstmt.setString(1, "70");
pstmt.setString(2, cont_no);
pstmt.setInt(3, int_cont_no2);
rs = pstmt.executeQuery();
if(rs.next()) {
//오라클의 함수들을 사용하기 위해 캐스팅
CLOB clob = ((OracleResultSet)rs).getCLOB(1);
Writer writer = clob.getCharacterOutputStream();
Reader src = new CharArrayReader(contents.toCharArray());
char[] buffer = new char[1024];
int read = 0;
while ((read = src.read(buffer, 0, 1024)) != -1) {
writer.write(buffer, 0, read);
}
src.close();
writer.close();
}
con.commit();
con.setAutoCommit(true);
} catch (SQLException se) {
throw se;
} finally {
pstmt.close();
con.close();
}
}
... 생략