ibatis+oracle blob类型字段insert update处理

我的开发框架是:webwork+ibatis+oracle

其中有个表的字段是blob类型的,当做insert操作时如果文件太大,超过4k时,就会报错,在网上找了好多处理类似问题的方法,都没有解决。

给大家介绍下我的解决方法,以帮助以后有类似问题的兄弟,呵呵。。。

表结构:

create table T_BULLETIN
(
  BULLETIN_ID      NUMBER(8) not null,
  TITLE            VARCHAR2(255),
  BULLETIN_CONTENT BLOB,
  SENDTIME         TIMESTAMP(6),
  SEND_NAME        VARCHAR2(100)
)

java类PO

package com.aspire.dsmmp.baseinfo.bulletin.po;

import java.io.Serializable;
import java.util.Date;
public class BulletinPO implements Serializable{
 private long bulletin_id;
  private String title;
 private String bulletin_content;
 private byte[] bulletin_content_byte;
 
 private Date sendtime;
 private String send_name;
 private long channel_id;
 private String web_short_name;
 private String bank_account_name;
 public BulletinPO() {
  super();
 }
 public long getBulletin_id() {
  return bulletin_id;
 }
 public void setBulletin_id(long bulletin_id) {
  this.bulletin_id = bulletin_id;
 }
 public String getTitle() {
  return title;
 }
 public void setTitle(String title) {
  this.title = title;
 }
 public String getBulletin_content() {
  return bulletin_content;
 }
 public void setBulletin_content(String bulletin_content) {
  this.bulletin_content = bulletin_content;
 }
 public byte[] getBulletin_content_byte() {
  return bulletin_content_byte;
 }
 public void setBulletin_content_byte(byte[] bulletin_content_byte) {
  this.bulletin_content_byte = bulletin_content_byte;
  String strResult = new String(bulletin_content_byte);
  this.setBulletin_content(strResult);
 }
 public Date getSendtime() {
  return sendtime;
 }
 public void setSendtime(Date sendtime) {
  this.sendtime = sendtime;
 }
 public String getSend_name() {
  return send_name;
 }
 public void setSend_name(String send_name) {
  this.send_name = send_name;
 }
 public long getChannel_id() {
  return channel_id;
 }
 public void setChannel_id(long channel_id) {
  this.channel_id = channel_id;
 }
 public String getWeb_short_name() {
  return web_short_name;
 }
 public void setWeb_short_name(String web_short_name) {
  this.web_short_name = web_short_name;
 }
 public String getBank_account_name() {
  return bank_account_name;
 }
 public void setBank_account_name(String bank_account_name) {
  this.bank_account_name = bank_account_name;
 }
}

ibatis sql insert配置文件

<insert id="insertBulletin" parameterClass="bulletinPO">
  <selectKey resultClass="long" keyProperty="bulletin_id">SELECT SEQ_BULLETIN_INFO.nextval AS bulletin_id FROM DUAL</selectKey>
  insert into t_bulletin (bulletin_id ,title , bulletin_content, sendtime, send_name) values
  (#bulletin_id#,#title#,#bulletin_content_byte#,#sendtime#,#send_name#)
 </insert>

webwork Action处理类里大对象字段对应的属性用String类型保存页面的值

private String bulletin_content;

在执行保存或更新的方法里,把字符串转换成byte数组保存到数据库就可以了

bulletinPO.setBulletin_content_byte(bulletin_content.getBytes());
   flg = bulletinService.insertBulletin(bulletinPO);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值