动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
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,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息



本月文章推荐
.驾驭“野马”-- 探索Java&n.
.用java编写的小游戏源代码分析.
.Eclipse3.1中体验J2SE5.0之泛型(.
.你的应用程序为.NET做好准备了吗.
.Hibernate入门.
.Java技术进阶 基于Java的IDEA加密.
.Struts生成Word下载.
.理解JTWI的具体内容和作用.
.抽象PACKAGES增加系统灵活性.
.Netscape服务器端编程技术.
.《Java 手机/PDA 程序设计入门》.
.javamail 处理html信件的方法,包.
.JSP/Servlet/JSF-Java异常框架设.
.AOP系列之三:用Java动态代理实现.
.怎样用java发送邮件.
.Win2k下Jboss、Tomcat和Apache的.
.java获取本机的ip地址.
.24点算法的java代码.
.Java Collections---HashMap深度.
.JDK5 新特性之新的格式化输出.

分享搞定的 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)

上一篇:测试概念进行代码设计时的七条基本原则 人气:443
下一篇:在 Java 程序设计中处理 DOM 异常 人气:283
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-7-9 顶级域名交易系统 v3.0 完整版
2008-7-9 ACTCMS网站管理系统 v2.0 Build
2008-7-9 Roclog v3.1.4 build 20080706
2008-7-9 乐彼网上开店系统(56770 Eshop)
2008-7-9 深度学习alexa排名提升专家 v1.0
2008-7-9 BBSXP 2008 Build 8.0.5 正式版
2008-7-9 一句话快速信息发布系统 修正完美
2008-7-9 ACTCMS网站管理系统 v2.0 Build
2008-7-9 乐涛涛留言本 08版
2008-7-5 AgileMessenger即时通讯工具 v1.
2008-7-5 GoodCalculator2.0版固件计算器
2008-7-5 RepoName源地址搜索工具 v1.21b
2008-7-5 AgileMessenger即时通讯工具 v1.
2008-7-5 TouchCopy多媒体管理软件 v3.13完
2008-7-5 VideosTone视频铃声 v1.1汉化破解
2008-7-5 TouchPad触摸板 v4.44破解版
2008-7-5 VideosTone破解补丁 v1.0
2008-7-5 Feeds GoogleReader客户端 v0.4.3


  发表评论
姓 名: 验证码:
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報