国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

分享搞定的 CLOB 字段存取的代碼

2019-11-18 12:05:45
字體:
來源:轉載
供稿:網友

  采用得是Oracle9i數據庫,Jboss或Weblogic。
  JDBC采用ORACLE9i自帶的Class12.jar
  -------------
  數據庫結構:
  代碼:
  
  CREATE TABLE SNCPARAMETERS
  (
   ID   NUMBER(19)               NOT NULL,
   SNCID NUMBER(19),
   NAME  VARCHAR2(255),
   VALUE CLOB
  )
   --------------
  BO采用xdoclet建立的:
  代碼:
  
  public class SNCParameters extends BaSEObject
  {
  
    /**
     * Returns the id.
     *
     * @return   long
     * @hibernate.id
     *     column = "id"
     *     type = "long"
     *     generator-class = "native"
     *     unsaved-value = "null"
     */
    public Long getId()
    {
      return id;
    }
  
    /**
     *  Sets the Id attribute of the SNCParameters object
     *
     * @param  id The new Id value
     */
    public void setId(Long id)
    {
      this.id = id;
    }
  
  
    /**
     * Returns the name.
     *
     * @return   String
     *
     * @hibernate.PRoperty
     *     column = "name"
     *     type = "string"
     *     not-null = "true"
     *     unique = "false"
     */
  
    public String getName()
    {
      return name;
    }
  
    /**
     *  Sets the Name attribute of the SNCParameters object
     *
     * @param  name The new Name value
     */
    public void setName(String name)
    {
      this.name = name;
    }
  
    /**
     * Returns the sncId.
     *
     * @return   Long
     *
     * @hibernate.property
     *     column = "sncId"
     *     type = "long"
     *     not-null = "true"
     *     unique = "false"
     */
  
    public Long getSncId()
    {
      return sncId;
    }
  
    /**
     *  Sets the SncId attribute of the SNCParameters object
     *
     * @param  sncId The new SncId value
     */
    public void setSncId(Long sncId)
    {
      this.sncId = sncId;
    }
  
    /**
     * Returns the values.
     *
     * @return   Clob
     *
     * @hibernate.property
     *     column = "value"
     *     type = "clob"
     *     not-null = "true"
     *     unique = "false"
     */
  
    public Clob getValue()
    {
      return value;
    }
  
    /**
     *  Sets the Values attribute of the SNCParameters object
     *
     * @param  values The new Values value
     */
    public void setValue(Clob value)
    {
      this.value = value;
    }
    private Long id;
    private Long sncId;
    private String name;
    private Clob value;
    private String valueString;
    public String getValueString()
    {
      return valueString;
    }
      public void setValueString(String valueString)
    {
      this.valueString = valueString;
    }
  }
  
  注:valueString并不映射到數據庫的CLOB字段,只是方便需要使用這個BO的人用GET、SET 處理這個巨長的CLOB字段
  ------------
  xdocLet生成的xml文件:
  代碼:
  
  <?xml version="1.0"?>
  
  <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
  
  <hibernate-mapping>
    <class
      name="com.idncn.mc.bo.SNCParameters"
      table="SNCParameters"
      dynamic-update="false"
      dynamic-insert="false"
    >
  
      <id
        name="id"
        column="id"
        type="long"
        unsaved-value="null"
      >
        <generator class="native">
        </generator>
      </id>
  
      <property
        name="name"
        type="string"
        update="true"
        insert="true"
        column="name"
        not-null="true"
        unique="false"
      />
  
      <property
        name="sncId"
        type="long"
        update="true"
        insert="true"
        column="sncId"
        not-null="true"
        unique="false"
      />
  
      <property
        name="value"
        type="clob"
        update="true"
        insert="true"
        column="value"
        not-null="true"
        unique="false"
      />
    </class>
  
  </hibernate-mapping>
  
  --------------------
  insert的代碼:
  代碼:
  
    public List batchAddSncParameters(List sncParametersList, Long sncId) throws DbaccessException
    {
      logger.enterMethod();
      List ret = new ArrayList();
      try
      {
        sess = getsession();
        if (sncParametersList != null && sncParametersList.size() > 0)
        {
          for (int i = 0; i < sncParametersList.size(); i++)
          {
            SNCParameters cp = (SNCParameters) sncParametersList.get(i);
            long newId = -1;
            if (cp != null)
            {
              SNCParameters cpNew = new SNCParameters();
              cpNew.setSncId(sncId);
              cpNew.setName(cp.getName());
              cpNew.setValue(Hibernate.createClob(" "));
              newId = ((Long) sess.save(cpNew)).longValue();
              sess.flush();
  
       sess.refresh(cpNew, LockMode.UPGRADE);
              String content = cp.getValueString();
  
              String appserver = System.getProperty("appserver", "jboss");
              if (!appserver.equalsIgnoreCase("jboss"))
              {
                //weblogic
                OracleThinClob clob = (OracleThinClob) cpNew.getValue();
                java.io.Writer pw = clob.getCharacterOutputStream();
                pw.write(content);
                pw.flush();
                pw.close();
       }
              else
              {
                //jboss
                oracle.sql.CLOB clob = (oracle.sql.CLOB) cpNew.getValue();
                java.io.Writer pw = clob.getCharacterOutputStream();
                pw.write(content)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台湾省| 澄城县| 兴义市| 吴江市| 项城市| 五寨县| 错那县| 二连浩特市| 西峡县| 东乌珠穆沁旗| 北碚区| 界首市| 阜南县| 肇州县| 原阳县| 松江区| 高青县| 乳山市| 广饶县| 黑龙江省| 南宁市| 栖霞市| 黔西| 聊城市| 扎兰屯市| 河西区| 诏安县| 车险| 兰考县| 青浦区| 陇西县| 漠河县| 托克托县| 米易县| 高陵县| 绥阳县| 盘山县| 周至县| 哈密市| 青冈县| 无极县|