锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品lv,亚洲大片免费观看,亚洲午夜成人精品无码色欲http://m.tkk7.com/louieling/category/18771.html瀛︿細鍋氫漢zh-cnSat, 03 Mar 2007 03:56:45 GMTSat, 03 Mar 2007 03:56:45 GMT60hibernate瀛樺彇鍥劇墖紺轟緥http://m.tkk7.com/louieling/archive/2006/12/28/90572.html璺槗璺槗Thu, 28 Dec 2006 11:26:00 GMThttp://m.tkk7.com/louieling/archive/2006/12/28/90572.htmlhttp://m.tkk7.com/louieling/comments/90572.htmlhttp://m.tkk7.com/louieling/archive/2006/12/28/90572.html#Feedback0http://m.tkk7.com/louieling/comments/commentRss/90572.htmlhttp://m.tkk7.com/louieling/services/trackbacks/90572.html涓鑸綉绔欏湪澶勭悊鐢ㄦ埛涓婁紶鍥劇墖鏃墮氬父閲囩敤涓ょ絳栫暐錛氫竴鏄洿鎺ユ妸鍥劇墖瀛樺叆鏁版嵁搴撲腑鐨凚lob瀛楁錛涗簩鏄暟鎹簱涓彧瀛樺偍鍥劇墖鐨勫湪鏈嶅姟鍣ㄤ笂鐨勮礬寰勪俊鎭狅紝鍥劇墖瀛樻斁鍦ㄥ垎闂ㄥ埆綾葷殑鏂囦歡涓紝浣跨敤鐨勬椂鍊欎粠鏁版嵁搴撹鍙栬礬寰勪俊鎭埌欏甸潰img鍏冪礌鍗沖彲錛庡湪姝や笉璁ㄨ涓ょ鏂規鐨勪紭鍔o紝鎴戝彧鏄啓浜嗕釜hibernate鐨勪緥瀛愭潵瀹炵幇絎竴縐嶇瓥鐣ワ紟渚嬪瓙寰堢畝鍗曪紝t_user琛ㄤ富瑕佷袱涓瓧孌碉紝name鍜宲hoto錛屽叾涓璸hoto瀛楁綾誨瀷涓築lob錛庡湪姝や緥涓暟鎹簱鎴戦噰鐢╩ysql錛宱racle鐨凚lob瀛楁姣旇緝鐗規畩錛屼綘蹇呴』鑷畾涔夌被鍨嬶紝鍏蜂綋鐨勮鑷鎼滅儲錛岃繖鏂歸潰鐨勮祫鏂欏緢澶氾紟

//User.java銆銆

package聽com.denny_blue.hibernate;

import聽java.io.Serializable;
import聽java.sql.Blob;

public聽class聽User聽implements聽Serializable{
聽private聽Integer聽id;
聽private聽String聽name;
聽private聽Blob聽photo;
聽/**
聽聽*聽@return聽the聽id
聽聽*/
聽public聽User(){
聽}
聽public聽Integer聽getId()聽{
聽聽return聽id;
聽}
聽/**
聽聽*聽@param聽id聽the聽id聽to聽set
聽聽*/
聽public聽void聽setId(Integer聽id)聽{
聽聽this.id聽=聽id;
聽}
聽/**
聽聽*聽@return聽the聽name
聽聽*/
聽public聽String聽getName()聽{
聽聽return聽name;
聽}
聽/**
聽聽*聽@param聽name聽the聽name聽to聽set
聽聽*/
聽public聽void聽setName(String聽name)聽{
聽聽this.name聽=聽name;
聽}
聽/**
聽聽*聽@return聽the聽photo
聽聽*/
聽public聽Blob聽getPhoto()聽{
聽聽return聽photo;
聽}
聽/**
聽聽*聽@param聽photo聽the聽photo聽to聽set
聽聽*/
聽public聽void聽setPhoto(Blob聽photo)聽{
聽聽this.photo聽=聽photo;
聽}

}


綾籙ser鏈夛紦涓睘鎬э紝id,name,photo錛岀浉搴旂殑getter鍜宻etter鏂規硶浠ュ強涓涓棤鍙傛瀯閫犲嚱鏁幫紟搴旇娉ㄦ剰鐨勬槸photo鐨勭被鍨媕ava.sql.Blob

鐩稿簲鐨剈ser.hbm.xml搴旇濡備笅錛?br />
<?xml聽version="1.0"?>
<!DOCTYPE聽hibernate-mapping聽PUBLIC
聽"-//Hibernate/Hibernate聽Mapping聽DTD聽3.0//EN"
聽" http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
<hibernate-mapping
聽package="com.denny_blue.hibernate">

聽<class聽name="com.denny_blue.hibernate.User"
聽聽聽聽聽聽聽聽table="t_user"
聽聽聽聽聽聽聽聽dynamic-update="true"
聽聽聽聽聽聽聽聽dynamic-insert="true"
聽聽聽聽聽聽聽聽batch-size="3">
聽聽<id聽name="id"
聽聽聽聽聽聽column="id"
聽聽聽聽聽聽type="java.lang.Integer">
聽聽聽<generator聽class="native"/>
聽聽</id>
聽聽<property聽name="name"聽column="name"聽type="java.lang.String"聽lazy="true"/>
聽聽<property聽name="photo"聽column="photo"聽type="java.sql.Blob"/>

聽</class>

</hibernate-mapping>

瀵瑰簲鐨刪ibernate.cfg.xml閰嶇疆鏂囦歡錛屼笉鍐嶅垪鍑猴紝璇峰弬鐓ibernate鏂囨。鑷璁懼畾錛?br />
錛極錛屽仛浜嗚繖涓姝ワ紝鎴戜滑鍐欎釜嫻嬭瘯綾繪潵榪涜鍗曞厓嫻嬭瘯錛?br />
package聽com.denny_blue.test;

import聽java.io.FileInputStream;
import聽java.io.FileNotFoundException;
import聽java.io.FileOutputStream;
import聽java.io.IOException;
import聽java.io.InputStream;
import聽java.sql.Blob;

import聽org.hibernate.Hibernate;
import聽org.hibernate.HibernateException;
import聽org.hibernate.Session;
import聽org.hibernate.SessionFactory;
import聽org.hibernate.Transaction;
import聽org.hibernate.cfg.Configuration;

import聽com.denny_blue.hibernate.User;

import聽junit.framework.TestCase;

public聽class聽HibernateTest聽extends聽TestCase聽{
聽聽聽聽聽聽聽聽private聽Session聽session;
聽protected聽void聽setUp()聽throws聽Exception聽{
聽聽try{
聽聽聽Configuration聽config=new聽Configuration().configure();
聽聽聽SessionFactory聽sf=config.buildSessionFactory();
聽聽聽session=sf.openSession();
聽聽}catch(HibernateException聽e){
聽聽聽e.printStackTrace();
聽聽}
聽}

聽protected聽void聽tearDown()聽throws聽Exception聽{
聽聽try{
聽聽聽session.close();
聽聽}catch(HibernateException聽e){
聽聽聽e.printStackTrace();
聽聽}
聽}

聽public聽void聽testSave()throws聽FileNotFoundException,IOException{
聽聽User聽user=new聽User();
聽聽user.setName("jordan");
聽聽FileInputStream聽in=new聽FileInputStream("C:\\test.gif");
聽聽Blob聽photo=Hibernate.createBlob(in);
聽聽user.setPhoto(photo);
聽聽Transaction聽tx=null;
聽聽try{
聽聽tx=session.beginTransaction();
聽聽session.saveOrUpdate(user);
聽聽tx.commit();
聽聽}catch(HibernateException聽e){
聽聽聽if(tx!=null)
聽聽聽聽tx.rollback();
聽聽聽e.printStackTrace();
聽聽}finally{
聽聽聽in.close();
聽聽}
聽}
聽public聽void聽testLoad()throws聽Exception{
聽聽try{
聽聽聽User聽user=(User)session.load(User.class,聽new聽Integer(1));
聽聽聽Blob聽photo=user.getPhoto();
聽聽聽InputStream聽in=photo.getBinaryStream();
聽聽聽FileOutputStream聽out=new聽FileOutputStream("C:\\out\\test2.gif");
聽聽聽byte聽[]聽buf=new聽byte[1024];
聽聽聽int聽len;
聽聽聽while((len=in.read(buf))!=-1){
聽聽聽聽out.write(buf,聽0,聽len);
聽聽聽}
聽聽聽in.close();
聽聽聽out.close();
聽聽}catch(HibernateException聽e){
聽聽聽e.printStackTrace();
聽聽}
聽}

}
鎴戜滑璇誨彇C鐩樼洰褰曚笅鐨則est.gif騫跺瓨鍌ㄥ埌鏁版嵁搴撲腑錛岀劧鍚庡啀鍙栧嚭鏉ュ啓鍏:\out鐩綍錛屾鏃朵綘鍙互鏌ョ湅涓嬫暟鎹〃涓璸hoto鏄劇ず涓篵lob,琛ㄧず宸茬粡鎴愬姛瀛樺叆錛庡肩殑娉ㄦ剰鐨勪唬鐮佺墖孌靛氨鏄細

FileInputStream聽in=new聽FileInputStream("C:\\test.gif");
聽聽Blob聽photo=Hibernate.createBlob(in);
鎴戜滑榪欓噷鏄粠紓佺洏涓鍙栧浘鐗囷紝瀹為檯搴旂敤涓綘鍙互鍒╃敤涓婁紶緇勪歡寰楀埌鍥劇墖鐨勶紥榪涘埗鏁版嵁嫻侊紝騫跺埄鐢℉ibernate.createBlob鏂規硶鏉ユ瀯閫犵浉搴旂殑Blob瀵硅薄錛庤屽彇鍥劇墖鍒欎嬌鐢?br />
InputStream聽in=photo.getBinaryStream();

榪欏彧鏄釜綆鍗曠殑嫻嬭瘯綾伙紝濡傛灉鎴戞兂浠庢暟鎹簱涓彇鍑哄浘鐗囧茍鐜板疄鍦ㄩ〉闈笂璇ュ浣曞仛鍛紵鍏跺疄涔熷緢綆鍗曪紝鎴戜滑鍏堣鍐欎竴涓猻ervlet錛屽湪瀹冪殑service鏂規硶涓彇鍑哄浘鐗囷紝騫訛紓鐢伙紓鍒版寚瀹氶〉闈笂錛?br />
package聽com.easyjf.asp.action;

import聽java.io.InputStream;
import聽java.io.OutputStream;
import聽java.sql.Blob;

import聽javax.servlet.ServletException;
import聽javax.servlet.http.HttpServlet;
import聽javax.servlet.http.HttpServletRequest;
import聽javax.servlet.http.HttpServletResponse;

import聽org.hibernate.HibernateException;
import聽org.hibernate.Session;
import聽org.hibernate.SessionFactory;
import聽org.hibernate.cfg.Configuration;
import聽com.denny)blue.hibernate.User;


public聽class聽Test聽extends聽HttpServlet聽{

聽/**
聽聽*聽Destruction聽of聽the聽servlet.聽<br>
聽聽*/
聽private聽Session聽session;
聽public聽void聽destroy()聽{
聽聽try{
聽聽聽session.close();
聽聽}catch(HibernateException聽e){
聽聽聽e.printStackTrace();
聽聽}
聽}

聽/**
聽聽*聽Initialization聽of聽the聽servlet.聽<br>
聽聽*
聽聽*聽@throws聽ServletException聽if聽an聽error聽occure
聽聽*/
聽public聽void聽init()聽throws聽ServletException聽{
聽聽try{
聽聽聽Configuration聽config=new聽Configuration().configure();
聽聽聽SessionFactory聽sf=config.buildSessionFactory();
聽聽聽session=sf.openSession();
聽聽}catch(HibernateException聽e){
聽聽聽e.printStackTrace();
聽聽}
聽}
聽聽聽聽public聽void聽doGet(HttpServletRequest聽request,HttpServletResponse聽response)
聽聽聽聽{
聽聽聽聽聽try{
聽聽聽User聽user=(User)session.load(User.class,聽new聽Integer(1));
聽聽聽Blob聽photo=user.getPhoto();
聽聽聽InputStream聽in=photo.getBinaryStream();
聽聽聽OutputStream聽out=response.getOutputStream();
聽聽聽byte聽[]聽buf=new聽byte[1024];
聽聽聽int聽len;
聽聽聽while((len=in.read(buf))!=-1){
聽聽聽聽out.write(buf,聽0,聽len);
聽聽聽}
聽聽聽in.close();
聽聽聽out.close();
聽聽}catch(Exception聽e){
聽聽聽e.printStackTrace();
聽聽}
聽聽聽聽}

}

閫氳繃response.getOutputStream鍙栧緱杈撳嚭嫻侊紝鍏朵粬灝變笌涓婃浠g爜涓鑷達紟servlet鍐欏ソ浜嗭紝鎬庝箞鍦ㄩ〉闈㈣皟鐢ㄥ憿錛熼偅灝辨洿綆鍗曞暒錛岀洿鎺ュ湪欏甸潰鐨刬mg鏍囩鐨剆rc灞炴т笂璋冪敤璇ervlet鍗沖彲錛屽錛?br />
<img聽id="test"聽src="/servlet/Test"/>


璺槗 2006-12-28 19:26 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 黑人精品videos亚洲人| 亚洲精品国产精品乱码视色| 三级黄色片免费看| 亚洲人成色在线观看| 久久九九亚洲精品| 亚洲无码日韩精品第一页| 成人免费视频小说| 免费不卡在线观看AV| a毛片全部免费播放| 黄色网址在线免费观看| 亚洲成熟丰满熟妇高潮XXXXX| 亚洲电影一区二区三区| 久久久久久亚洲精品| 亚洲国产精品无码久久久不卡| 亚洲成网777777国产精品| 国产大片线上免费看| 国产a级特黄的片子视频免费 | 亚洲AV无码一区东京热久久 | 999国内精品永久免费观看| 皇色在线免费视频| 99视频免费播放| 99视频在线看观免费| 国内精品免费视频自在线| 大学生一级特黄的免费大片视频| 久久国内免费视频| 国产男女猛烈无遮挡免费视频| 亚洲AV无码成人精品区大在线| 国产精品亚洲综合一区| 99亚洲精品高清一二区| 亚洲一级毛片免费观看| 黄色一级视频免费| 99视频在线免费| 亚洲国产中文v高清在线观看| 亚洲色精品vr一区二区三区| 国产AV无码专区亚洲AV毛网站| 亚洲高清视频在线播放| 亚洲一区AV无码少妇电影| 一区二区三区免费视频网站| 久久国产精品免费看| 亚洲 国产 图片| 亚洲人成影院77777|