2016-07-23 59 views
0

我想问你,如何在数据库中存储文件的最佳方式是什么。如何使用休眠存储数据库中的文件

最适合使用哪种数据类型?

我尝试使用byte[],但生成数据库方案存在很多问题。注释集mediumblob无法正常工作。

我读了很多教程,但从来没有工作!我的冬眠总是会产生tinyblob

你能帮助我吗?

我正在使用MySQL。

+0

你试过LONGBLOB? – Pankaj

+0

是的,但方案总是生成tinyblob – clougioc

+0

你可以发布模型。 – Priyamal

回答

0

我想你应该保存你的数据在Blob里面java.sql.Blob; 包假设你有这样的模型。

import java.sql.Blob; 
public class folder{ 
    public Blob file; 

    public Blob getFile() { 
     return file; 
    } 

    public void setFile(Blob file) { 
     this.file = file; 
    } 
} 

去下面的方法,来

byte[] FileBytes = //read file and assign to byte array 
    folderOb.setFile(photoBytes);//you don't need to set a Blob just pass a byte array 
    session.save(folderOb); //saving in the database 

更改XML映射保存文件夹对象本

<property name="file" column="file" type="blob" />

相关问题