求Oracle CLOB 和 BLOB 读写 例子 50分

时间:2008-07-24 09:24:08   来源:论坛整理  作者:  编辑:chinaitzhe
求Oracle CLOB 和 BLOB 读写 例子 能用 立即给分
网友回复:此回复为自动发出,仅用于显示而已,并无任何其他非凡作用
楼主【sy_22841597】截止到2008-07-21 16:06:10的历史汇总数据(不包括此帖):
发帖的总数量:17 发帖的总分数:220 每贴平均分数:12
回帖的总数量:21 得分贴总数量:4 回帖的得分率:19%
结贴的总数量:17 结贴的总分数:220
无满足结贴数:9 无满足结贴分:240
未结的帖子数:0 未结的总分数:0
结贴的百分比:100.00% 结分的百分比:100.00%
无满足结贴率:52.94 % 无满足结分率:109.09%
敬礼!
网友回复:/**
* Oralce CLOB 字段更新
*
* @param sql
* String : sql 语句
* @param bdata
* byte[] : 大字段值
* @return int
* @throws Exception
*/
public int ExecuteUpdateOracleClob(String tableName,
String clobField, String pkField, String pkValue, String clobContent)
throws Exception {
int iret = 0;
PreparedStatement pst = null;
Connection Conn = null;
try {
Conn = GetConnection();
Conn.setAutoCommit(false);

pst = Conn.prepareStatement("update " tableName " set "
clobField "=? where " pkField "=?");
pst.setClob(1, oracle.sql.CLOB.empty_lob());
pst.setObject(2, pkValue);
pst.executeUpdate();

pst = Conn.prepareStatement("select " clobField " from "
tableName " where " pkField "=?");
pst.setObject(1, pkValue);
ResultSet rset = pst.executeQuery();

oracle.sql.CLOB resClob = null;
if (rset.next())
resClob = (oracle.sql.CLOB) rset.getClob(1);

rset.close();

resClob.putString(1, clobContent);

pst = Conn.prepareStatement("update " tableName " set "
clobField "=? where " pkField "=?");
pst.setClob(1, resClob);
pst.setObject(2, pkValue);
iret = pst.executeUpdate();

Conn.commit();

} catch (Exception ex) {
try {
Conn.rollback();
CloseConn(Conn, pst);
} catch (SQLException sqlex) {
}
System.out.println(ex.toString());
throw new Exception("ExecuteUpdateOracleBlob:" ex.toString());
} finally {
CloseConn(Conn, pst);
}
return iret;
}

/**
* 执行大字段查询
*
* @param sql
* String : sql 语句
* @return byte[] : 返回大字段内容
* @throws Exception
*/
public String ExecuteQueryClob(String sql) throws Exception {
Statement st = null;
ResultSet rs = null;
Connection Conn = null;
char retdata[] = null;
String result = "";
try {
Conn = GetConnection();
st = Conn.createStatement();
rs = st.executeQuery(sql);
if (rs.next()) {
Clob cdata = rs.getClob(1);
if (cdata != null) {
retdata = new char[(int) cdata.length()];
cdata.getCharacterStream().read(retdata);
result = String.valueOf(retdata);
}
}
} catch (Exception ex) {
try {
Conn.rollback();
CloseRs(rs);
CloseConn(Conn, st);
} catch (SQLException sqlex) {
}
throw new Exception(ex.toString());
} finally {
CloseRs(rs);
CloseConn(Conn, st);
}
return result;
}
关键字:Oracle,CLOB,BLOB,读写,例子,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面