求Oracle CLOB 和 BLOB 读写 例子 能用 立即给分
解决方案 »
- 求助 解决一个问题!
- 郁闷死我了呜呜,图片怎么显示不出来呢?路径没有错啊。。大家帮助些谢谢
- 问个JSP EL的菜鸟问题
- 在tomcat下 自定义的JSP项目下 找不到jsp页面
- javax.servlet.的request问题
- 如何读取并显示数据库中存放的图片
- 求一个select,可以输入选项的
- jsp做个投票系统,如果设置一个IP只能投票一次。
- jsp 中<a > target 标签的问题
- servlet中如何存放、传递、调用数据库中字段类型不同的数据集的问题----及不同类型对象的存取
- struts中如果提交 表单的内容为空时候,返回首页的问题。easy question
- Tomcat5.5.25启动,停止,重起命令
* 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;
}