posts - 31,  comments - 31,  trackbacks - 0

          1、數據實體Bean
          public class Temp?implements Serializable
          {
          ??? private java.lang.Long???? id;
          ??? private Blob??????????????????? object; //用于存放對象的Blob
          ??? private java.lang.Long???? userId;
          ??? private java.util.Date?????? appendDate;
          }

          2、hbm影射
          <hibernate-mapping package="temp">
          <class name="Temp" table="TEMP">
          ??????? <id name="id" column="ID" type="long">
          ??????????? <generator class="sequence">
          ??????????? ?<param name="sequence">TEMP_SEQ</param>
          ??????????? </generator>
          ??????? </id>
          ???????? <property name="object" column="OBJECT" type="blob" />
          ??????? <property name="userId" column="USER_ID" type="long" />
          ??????? <property name="appendDate" column="APPEND_DATE" type="date" />
          ??? </class>?
          </hibernate-mapping>

          3、save方法
          public void saveTemp( ) throws IOException, ClassNotFoundException, SQLException
          ?{
          ???????Temp temp = new Temp();
          ????????temp.setUserId(new Long(1));
          ????????temp.setAppendDate(new Date());
          ????????ByteArrayOutputStream outputstr = new ByteArrayOutputStream();
          ????????ObjectOutputStream objOutStr = new ObjectOutputStream( outputstr );
          ????????objOutStr.writeObject( contract );????????????????????????? //contract為要保存的對象;
          ????????BlobImpl blob = new BlobImpl(outputstr.toByteArray());
          ????????temp.setObject( blob );
          ????????saveTemp(temp);?????????????????????????????????????????????????????//將Temp持久化到數據庫;
          ?}
          4、get方法
          public void etTempList() throws IOException, ClassNotFoundException, SQLException
          ?{
          ????????List Templist = getTempList( userId);
          ????????if( contractTemplist.size() != 0 )
          ????????{
          ????????????????Temp temp = ( Temp )Templist.get(0);
          ???????????????ObjectInputStream instr = new ObjectInputStream(temp.getObject().getBinaryStream());
          ????????????????Contract contract = ( Contract )instr.readObject();
          ???????????}
          ?}

          posted on 2006-09-24 16:24 小平 閱讀(540) 評論(0)  編輯  收藏 所屬分類: java
          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          framework

          j2me

          java

          linux

          web

          其他

          友情鏈接

          素材

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 徐汇区| 滨州市| 息烽县| 分宜县| 金塔县| 屏东市| 彰化县| 同心县| 石嘴山市| 谢通门县| 革吉县| 文成县| 家居| 宁津县| 新昌县| 宁强县| 全椒县| 麻江县| 新巴尔虎右旗| 和龙市| 富民县| 冷水江市| 南和县| 防城港市| 阿拉尔市| 虎林市| 嘉禾县| 揭西县| 仙桃市| 高清| 永靖县| 山东| 尼玛县| 横山县| 会理县| 吉水县| 新巴尔虎右旗| 横峰县| 阳泉市| 松潘县| 景德镇市|