public void addOneComment(DocComment docComment) throws DocCommentManagerException {
    // TODO Auto-generated method stub
    PreparedDBUtil preparedDB = new PreparedDBUtil();
    DBUtil dbUitl = new DBUtil();

    String sql =
        "insert into td_cms_doc_comment(comment_id, doc_id,doc_comment,user_name,comtime,user_ip,src_comment_id,status) values(?, ?,?,?,?,?,?,?)";
    try {

      int id =
          (Integer)
              dbUitl.executeSelectForObject(executor.getSql("getCommentNextId"), Integer.class);
      preparedDB.preparedInsert(sql);
      preparedDB.setInt(1, id);
      preparedDB.setInt(2, docComment.getDocId());
      preparedDB.setClob(3, docComment.getDocComment(), "doc_comment");
      preparedDB.setString(4, docComment.getUserName());
      preparedDB.setTimestamp(5, new Timestamp(new Date().getTime()));
      preparedDB.setString(6, docComment.getUserIP());
      if (docComment.getSrcCommentId() == 0) preparedDB.setNull(7, Types.NUMERIC);
      else preparedDB.setInt(7, docComment.getSrcCommentId());
      preparedDB.setInt(8, docComment.getStatus());
      preparedDB.executePrepared();
    } catch (SQLException e) {
      e.printStackTrace();
      throw new DocCommentManagerException("新评论插入失败!" + e.getMessage());
    } finally {
      preparedDB.resetPrepare();
    }
  }
示例#2
0
  /** clob字段的写入 */
  @Test
  public void testClobWrite() {
    PreparedDBUtil dbUtil = new PreparedDBUtil();
    try {
      dbUtil.preparedInsert("insert into test(id,clobname) values(?,?)");

      dbUtil.setString(1, DBUtil.getNextStringPrimaryKey("test"));
      dbUtil.setClob(2, "clobvalue"); // 直接将字符串存储到clob字段中
      dbUtil.executePrepared();

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {

    }
  }
示例#3
0
  /** 针对oracle Clob字段的插入操作 */
  @Test
  public void testBigClobWrite() {
    PreparedDBUtil dbUtil = new PreparedDBUtil();
    TransactionManager tm = new TransactionManager();
    try {
      // 启动事务
      tm.begin();
      // 先插入一条记录,blob字段初始化为empty_lob
      dbUtil.preparedInsert("insert into test(id,clobname) values(?,?)");
      String id = DBUtil.getNextStringPrimaryKey("test");
      dbUtil.setString(1, id);
      dbUtil.setClob(2, CLOB.empty_lob()); // 先设置空的blob字段

      dbUtil.executePrepared();

      // 查找刚才的插入的记录,修改blob字段的值为一个文件
      dbUtil = new PreparedDBUtil();
      dbUtil.preparedSelect("select clobname from test where id = ?");
      dbUtil.setString(1, id);
      dbUtil.executePrepared();

      CLOB clob = (CLOB) dbUtil.getClob(0, "clobname");
      if (clob != null) {
        DBUtil.updateCLOB(clob, new java.io.File("d:\\route.txt"));
      }
      tm.commit();

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      try {
        tm.rollback();
      } catch (RollbackException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    } finally {
      tm = null;
      dbUtil = null;
    }
  }