网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.深入探讨SQL Server 2000对XML的.
.剖析.Net下的数据访问层技术(6).
.JDK开发工具包.
.使用JDBC和Hibernate来写入Blob型.
.野马的性格 Java SE 6.0新特性体.
.Java实现SOA的标准途径.
.无状态Enterprise JavaBeans的观.
.JAVA入门教程:运算符和表达式.
.J2EE应用程序打包与部署之一.
.JAVA链接DB2数据库的例子.
.各类Java资源收集(更新中……).
.EJB 2.1中实现Web Service.
.向 MIDP2.0 窗体加入自定义项目.
.GetSpecialFolder 方法.
.学习XHTM+CSS2.0制作标准站点方法.
.java bean 与 ejb的区别.
.让第一个jdo的应用跑起来.
.突破Java异常处理规则.
.基于CORBA/WEB技术构建三层体系结.
.为什么extends是有害的(二).

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

发表日期:2008-1-5



  采用得是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)
上一篇:测试概念进行代码设计时的七条基本原则 人气:624
下一篇:在 Java 程序设计中处理 DOM 异常 人气:505
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐