weblogic+oracle中使用clob类型数据

本文提供了两种关于模板数据的操作方法:一种是通过指定参数插入新的模板数据;另一种是根据模板编号更新现有的模板内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 /**
  * 添加模版数据
  * @param objCommonTemplateVO
  * @return
  * @throws TemplateException
  */
 public int insertCommonTemplate(CommonTemplateVO objCommonTemplateVO)
   throws TemplateException {
  Connection conn = null;
  PreparedStatement pstmtInsert = null;
  String strInsert = "INSERT INTO PUB_COMMON_TEMPLATE(TEMPLATE_ID,TEMPLATE_NAME,RELATION_PROJECT,RELATION_MODEL,RELATION_OBJECT,TEMPLATE_CONTENT,EXPORT_TYPE,REMARK) VALUES(?,?,?,?,?,EMPTY_CLOB(),?,?)";
  try {
   // 设置数据库连接
   conn = getConnection();
   pstmtInsert = conn.prepareStatement(strInsert, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
   pstmtInsert.setInt(1, objCommonTemplateVO.getTemplateId());
   pstmtInsert.setString(2, objCommonTemplateVO.getTemplateName());
   pstmtInsert.setString(3, objCommonTemplateVO.getRelationProject());
   pstmtInsert.setString(4, objCommonTemplateVO.getRelationModel());
   pstmtInsert.setString(5, objCommonTemplateVO.getRelationObject());
   pstmtInsert.setString(6, objCommonTemplateVO.getExportType());
   pstmtInsert.setString(7, objCommonTemplateVO.getRemark());
   pstmtInsert.executeUpdate();
  } catch (Exception ex) {
   logger.error("添加模版时出错", ex);
   throw new TemplateException("添加模版时出错", ex);
  } finally {
   this.closeConnection(pstmtInsert, conn);
  }
  return objCommonTemplateVO.getTemplateId();
 }

 /**
  * 根据模版编号修改模版内容
  * @param iTemplateId 模版编号
  * @param strTemplateContent 模版内容
  * @throws TemplateException
  */
 public int updateTemplateContent(int iTemplateId, String strTemplateContent) throws TemplateException {
  ResultSet rs = null;
  Connection conn = null;
  PreparedStatement pstmt = null;
  Writer outStream = null;
  String strQuery = "SELECT PC.TEMPLATE_CONTENT FROM PUB_COMMON_TEMPLATE PC WHERE PC.TEMPLATE_ID = ? FOR UPDATE";
  try {
   // 设置数据库连接
   conn = getConnection();
   pstmt = conn.prepareStatement(strQuery, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
   pstmt.setInt(1, iTemplateId);
   rs = pstmt.executeQuery();
   rs.next();
   OracleThinClob templateContent = (OracleThinClob) rs.getClob("TEMPLATE_CONTENT");
   outStream = templateContent.getCharacterOutputStream();
   char[] c = strTemplateContent.toCharArray();
   outStream.write(c, 0, c.length);
   outStream.flush();
   outStream.close();
  } catch (Exception ex) {
   logger.error("插入模版内容时出错", ex);
   throw new TemplateException("插入模版内容时出错", ex);
  } finally {
   this.closeConnection(rs, pstmt, conn);
  }
  return iTemplateId;
 }

阅读(617) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-11-06 08:51:36

呵呵 高手,我感觉这就是一个数据库的操作 有效代码也不过几行 感觉没什么好优化的方式 高手把你写的给贴出来看看啊

chinaunix网友2008-11-05 17:46:54

我靠,我发现我的实现给你的类同,强人,不过我是结合Spring实现的,感觉自己写的东西要少了很多. 我的站点,欢迎来访:http://www.wanjidong.cn

评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值