方法一:保存成文件,在数据库中存文件地址
方法二:
// --------------------
@Entity
@Table(name = "st_article")
public class Article{
@Id
@GeneratedValue
private int id;
private String author;
private String title;
private Date releaseDate;
/**
* in Mysql database, it corresponds to the 'longtext' type;
* in Oracle database, it corresponds to the '???' type.// 没实践过
*/
private Clob content;
......
}
在oracle中,有4个大对象(lobs)类型可用,分别是blob,clob,bfile,nclob。
下面是对lob数据类型的简单介绍。
blob: 二进制lob,为二进制数据,最长可达 4GB,存贮在数据库中。
clob: 字符lob,字符数据,最长可以达到 4GB, 存贮在数据库中。
bfile: 二进制文件;存贮在数据库之外的只读型二进制数据,最大长度由操作系统限制。
nclob:支持对字节字符集合(nultibytecharacterset)的一个clob列。
/**
* String 2 Clob
* @param content
*/
public void setContent(String content) {
try {
this.content = new javax.sql.rowset.serial.SerialClob(content
.toCharArray());
} catch (SerialException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getContent() {
StringBuilder sb = new StringBuilder();
BufferedReader reader = null;
if (content != null) {
try {
reader = new BufferedReader(content.getCharacterStream());
} catch (SQLException e) {
e.printStackTrace();
}
try {
String st = "" ;while ((st = reader.readLine()) != null) {
strBuilder.append(st + "\r\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
return strBuilder.toString();
}