Oracle 中Clob 类型数据的处理

[b]public void InsertContents(MContent content)[/b]
throws Exception {
String Title=content.getTitle() ;
String contents=content.getContents();
Connection sqlConn = null;
sqlConn = getConnection();
sqlConn.setAutoCommit(false); // *
//id, column_code, title, createdate, contenturl, contents
String sql = "insert into M_Content (column_code, title, createdate, contenturl, contents,filePath )values('"+content.getColumnCode()+
"','"+content.getTitle()+"',default,'"+content.getContentUrl()+ "',empty_clob(),'"+content.getFilePath()+"')";
System.out.println(sql);
Statement stmt = sqlConn.createStatement();
stmt.executeUpdate(sql);

sqlConn.commit(); // *
String strSQL = "select ID from M_Content where title='" + Title
+ "' and ROWNUM<=1 order by ID DESC";
System.out.println(strSQL);
String[][] array = ShareProcedure.getResultSet(strSQL);
if (array != null) {
sql = "select contents from M_Content where id=" + array[0][0]
+ " for update ";
System.out.println(sql);
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
java.sql.Clob clob = rs.getClob(1);
clob.setString(1, contents);
sql = "update M_Content set contents=? where id=" + array[0][0];
System.out.println(sql);
PreparedStatement pstmt = sqlConn.prepareStatement(sql);
pstmt.setClob(1, clob);
pstmt.executeUpdate();
sqlConn.commit();
}
}
stmt.close();
sqlConn.close();
System.out.println("content insert successful!");

}


[b] public boolean update(MContent content){[/b]

String sqlUpdate=" update M_Content set contents=empty_clob() where id="+content.getId();

String sql = "select contents from M_Content where id=" +content.getId()+ " for update ";
Connection con=pubecti.ShareProcedure.getConnection();
try {
ps=con.prepareStatement(sql);
Statement st=con.createStatement();
st.executeUpdate(sqlUpdate);
con.commit();

ResultSet rs = ps.executeQuery(sql);
if(rs.next()) {
java.sql.Clob clob = null;


clob = rs.getClob(1);
if(content.getContents()!=null){
clob.setString(1, content.getContents());
}else{
clob.setString(1, "");
}
String strSql="update M_Content set title=?,column_code=?,contenturl=?,contents=? ,filePath=? where id="+content.getId();
System.out.println("MContentDAO Update sql is:"+strSql);
ps=con.prepareStatement(strSql.toString());//PreparedStatement ps=null;
ps.setString(1, content.getTitle());
ps.setString(2, content.getColumnCode());
ps.setString(3, content.getContentUrl());
ps.setClob(4, clob);
ps.setString(5, content.getFilePath());
ps.executeUpdate();
con.commit();
ps.close();
st.close();
rs.close();
con.close();
return true;
}
}catch(SQLException e){
log.error("MContentDAO Update () 操作失败"+e.toString());
return false;
}catch(Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return false;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值