锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲国产精品lv,亚洲大片免费观看,亚洲午夜成人精品无码色欲http://www.tkk7.com/louieling/category/18771.html瀛︿細鍋氫漢zh-cnSat, 03 Mar 2007 03:56:45 GMTSat, 03 Mar 2007 03:56:45 GMT60- hibernate瀛樺彇鍥劇墖紺轟緥http://www.tkk7.com/louieling/archive/2006/12/28/90572.html璺槗璺槗Thu, 28 Dec 2006 11:26:00 GMThttp://www.tkk7.com/louieling/archive/2006/12/28/90572.htmlhttp://www.tkk7.com/louieling/comments/90572.htmlhttp://www.tkk7.com/louieling/archive/2006/12/28/90572.html#Feedback0http://www.tkk7.com/louieling/comments/commentRss/90572.htmlhttp://www.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"/>

]]>
主站蜘蛛池模板:
亚洲色一色噜一噜噜噜|
女人18毛片水真多免费看|
国产精品亚洲二区在线观看|
亚洲AV日韩AV永久无码色欲|
处破痛哭A√18成年片免费|
亚洲日本视频在线观看|
2019中文字幕免费电影在线播放|
亚洲人成电影福利在线播放
|
久久午夜夜伦鲁鲁片免费无码影视
|
亚洲精品tv久久久久久久久|
中文字幕乱码免费看电影|
亚洲桃色AV无码|
免费无码成人AV在线播放不卡|
亚洲AV无码乱码在线观看裸奔|
亚洲免费视频在线观看|
亚洲电影唐人社一区二区|
999国内精品永久免费观看|
色偷偷女男人的天堂亚洲网
|
亚洲国产精品一区二区九九|
一级日本高清视频免费观看
|
青青操免费在线视频|
久久亚洲AV成人无码电影|
亚洲毛片在线免费观看|
亚洲精品蜜夜内射|
亚洲成aⅴ人片久青草影院|
最近免费字幕中文大全|
亚洲视频中文字幕在线|
四虎影院免费视频|
一道本不卡免费视频|
亚洲AV乱码久久精品蜜桃|
成人福利免费视频|
国产亚洲女在线线精品|
亚洲精品少妇30p|
精品久久久久成人码免费动漫|
狠狠入ady亚洲精品|
日本亚洲成高清一区二区三区|
久久精品毛片免费观看|
色窝窝亚洲av网|
亚洲色图视频在线观看|
国产一区二区三区在线免费|
日本一道本不卡免费|