我的开发框架是: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);