日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hibernate oracle boolean 数据类型,用hibernate向oracle读取blob数据类型为并下载到本地...

發(fā)布時間:2024/4/19 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hibernate oracle boolean 数据类型,用hibernate向oracle读取blob数据类型为并下载到本地... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

向Oracle讀取16進制byte[]數(shù)據(jù)

這種方法只能處理總大小小于6M的數(shù)據(jù)(在默認的java虛擬機設置下)。

①持久化類:

public class Mail implements Serializable {

/**

* 主鍵

*/

private int id;

/**

* 即將傳入數(shù)據(jù)庫中的文件

*/

private byte[] filedata;

/*此處省略get、set*/

}

②持久化類與hibernate的映射文件:持久化類.hbm.xml

③HibernateUtil.java文件(這個不用去理解復制下來就可以)

import org.hibernate.SessionFactory;

import org.hibernate.cfg.Configuration;

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {

try {

// Create the SessionFactory from hibernate.cfg.xml

sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex) {

// Make sure you log the exception, as it might be swallowed

System.err.println("Initial SessionFactory creation failed." + ex);

throw new ExceptionInInitializerError(ex);

}

}

public static SessionFactory getSessionFactory() {

return sessionFactory;

}

}

④用hibernate來讀取并下載到本地:

public class TheMain {

/**

* @param args

*/

public static void main(String[] args) {

//例行公事的兩句,不要忘了任何hibernate操作都要用到的

Session session = HibernateUtil.getSessionFactory().openSession();

Transaction tran = session.beginTransaction();

File forDownFile = new File("D:/被下載的數(shù)據(jù).jpg");

//從數(shù)據(jù)庫請求數(shù)據(jù)

Mail mail = (Mail) session.load(Mail.class, 4);

//如果不要求下載那么寫到這里已經(jīng)足夠

FileOutputStream fos = null;

try {

//載入文件路徑

fos = new FileOutputStream(forDownFile);

//寫入文件數(shù)據(jù)

fos.write(mail.getFiledata());

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

//一定不要忘了釋放資源

fos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

總結

以上是生活随笔為你收集整理的hibernate oracle boolean 数据类型,用hibernate向oracle读取blob数据类型为并下载到本地...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。