??xml version="1.0" encoding="utf-8" standalone="yes"?>精品久久久久中文字幕小说,caoporn国产精品免费视频,日韩精品亚洲视频 http://www.aygfsteel.com/Michael-Q/articles/134133.htmlQBing_M QBing_M Thu, 02 Aug 2007 16:40:00 GMT http://www.aygfsteel.com/Michael-Q/articles/134133.html http://www.aygfsteel.com/Michael-Q/comments/134133.html http://www.aygfsteel.com/Michael-Q/articles/134133.html#Feedback 0 http://www.aygfsteel.com/Michael-Q/comments/commentRss/134133.html http://www.aygfsteel.com/Michael-Q/services/trackbacks/134133.html JDBC高应用
转自 http://www.blogcn.com/user69/galiasun/index.html
本来想l谈JDBC的高U连l方?事务模式.但发现关于大对象存储有很多h在问,所?br>先来插入一节关于大对象存储的内?然后再接着原来的思\写下?
JDBC的大对象存储听v来复?其实如果你明白了原理以后,非常简?|上有关q方面的 教材很少,而SUN的文档中,我从1.2开始看C在仍然是错误?不知道写文档的h长脑子没 ?那几行代码你试试不q道了,q么多次重抄下来q是错误?
大对象分c?一般来?大对象分?大的文本对象,比如一个很长的文本(请你要注意什么是 文本文g,什么是二进制文?文g,或者是你定义的一个长字符?比如你定义了: String s = "我们要去吃饭?.....................然后睡觉!"; 从吃饭到睡觉中间省略了实际的10000000000000?虽然你不会真的定义这么称的String,?br>有时会从什么地方得到这LString,要写到数据库? 另一U就是大的二q制对象,象执行文?图象文g{?注意,word,excel,pptq些"带格?的文 档都应该以二q制对象存储.
一般来?数据库如果支持大对象存储,会有q几U类型的SQL数据cd: BLOB,CLOCB,NLOB,也有的数据数只有一UBLOB,基本上是q样?BLOB用来存放二进制文??br>CLOB用来存放文本文g,NLOB是对多字节文本文件支?假如你的文本文g是纯英文?攑֜ BLOB中当然可?也就是说它是以byte格式存储?而多字节是以CHAR格式存储?
同样对于q几U类型的文档,有几U相对应的存取方? setter: 利用PreparedStatement的setXXXҎ, setAsciiStream()Ҏ用于写入一般的文本?setBinaryStream()Ҏ用于写入二进制流 而setUnicodeStream()用于写好UNICODE~码的文?与此相对应的ResultSet中三个getterҎ 用于取回:getAsciiStream(),getBinaryStream(),getBinaryStream(). 对于文g本n,要把它作Z个流,只要new InputStream(new FileInputStream("文g路径") 可以了,但对于大的String对象,你不会写入文件再转换成输入流? new StringBufferInputStream(String s),C? JDBC2以后提供了java.sql.BLOB对象,我不大家使用?一是很ȝ,二是Ҏ出错,要先?br>入一个空的BLOB对象,然后再填充它,实在没有必要,直接setXXXp?我试q?臛_mysql, oracle,sql server是可以直接set? 好了,我们先看一个例子如何写入文件到数据? 数据l构: create table test( name varchar(200), content BLOB ); File f = new File("a.exe";//先生成File对象是ؓ了取得流的长?FileInputStram可以直接 //传入文g路径 InputStream in = new InputStream(new FileInputStream(f)); PreparedStatement ps = conn.prepareStatement("insert into test (?,?)"; ps.setString(1,"a.exe"); ps.setBinaryStream(2,in,(int)f.length()); ps.executeUpdate(); f的长度一定要做从long到int的{?SUN的文档中好几版都没有改过?p么简?当然,不同?br>数据库存本n要设|它允许的最大长?MYSQL默认只能?M的文?要修改参数原能存更大的文? 如果要从数库中取得文? PreparedStatement ps = conn.prepareStatement("select * from test where name=?"); ps.setString(1,"a.exe"; ResultSet rs = ps.executeQuery(); if(rs.next()){ InputStream in = rs.getBinaryStream("content"; } 得到in对象?你可以进行Q何处?写向文g和写向页面只是out对象不同而已: 写向文g: DateOutputStream out = new DateOutputStream(new FileOutputStream("b.exe"); 写向面: response.reset(); response.setContType("cd"; ServletOutputSreamt out = response.getOutputSream(); 得到out对象?可以输Z: byte[] buf = new byte[1024]; int len = 0; while((len = in.read(buf)) >0) out.write(buf,0,len); in.close(); out.close(); 对于向页面输?要设|什么样的ContType,要看你想如何输出,如果你想让对方下?p?br>"application/octet-stream",q样即是文?图象都会下蝲而不会在览器中打开.如果你要?br>在浏览器中打开,p讄相应的类?q要在容器的配置文g中设|支持这U文档类型的输出,?br>对于很多格式的文?到底要输Z么类?其实是HTTP的MIME?比如囄:image/gif,当然你如 果你的文件扩展名(ext)不确?你也不要用if(ext.equals("gif")......q样来判?我教你一?br>技?我之所以说是技?是我没有在别的地方发现有人用q种Ҏ,Ҏ来说我是l对不会把别人的 Ҏ拿来说是我的技巧的: 构造一个filecd的URL,我们知道URL目前JAVA可以支持HTTP,FTP,MAILTO,FILE,LDAP{?从FILEcd 的URL可以得到它的MIME:
URL u = new URL("file://a.exe "; String mime = u.openConnection().getContentType(); q样你就可以直接response.setContType(mime);而不用一个一个类型判断了. 好了,大对象存储就说到q儿,不同的数据仍然和些特D的规定,不在此一一列D?
]]>攉客户端开发经典javascriptҎ http://www.aygfsteel.com/Michael-Q/articles/133467.htmlQBing_M QBing_M Mon, 30 Jul 2007 17:02:00 GMT http://www.aygfsteel.com/Michael-Q/articles/133467.html http://www.aygfsteel.com/Michael-Q/comments/133467.html http://www.aygfsteel.com/Michael-Q/articles/133467.html#Feedback 0 http://www.aygfsteel.com/Michael-Q/comments/commentRss/133467.html http://www.aygfsteel.com/Michael-Q/services/trackbacks/133467.html 1。字W串替代Ҏ? function String_Replace(srcString,findString,replaceString){ return String_ReplaceB(srcString, findString, replaceString, 0); } function String_ReplaceB(expression, find, replacewith, start) { var index = expression.indexOf(find, start); if (index == -1) return expression; var findLen = find.length; var newexp = ""; newexp = expression.substring(0, index)+(replacewith)+(expression.substring(index+findLen)); return String_ReplaceB(newexp, find, replacewith, index+1+findLen); } 2。取字符串长度方? function String_GetLength(str){ var i,rt=0; for(i=0;i<str.length;i++) { rt++; if(str.charCodeAt(i)>256)rt++; } return rt; } 3。求点数方? function getFloat(num) { var num = parseFloat(num); if(isNaN(num))num = 0; return num; } 4。求整数ҎQ用到QҎ取法Q? function getInt(num) { return parseInt(getFloat(num)); } 5。判断文本域对象是否惟空 function at_checkBlank(obj,caption) { if(String_Replace(obj.value," ","")=="") { obj.select(); alert(caption+"不能为空¡"); obj.focus(); return false; } return true; } 6。两个Select对象(llist,rlist)互相操作 var llist = fmObj.AssignedUser;//左边已经选中目 var rlist = fmObj.WaitedUser;//双未被选中的项? //双击双select中的目 function AssignUser() { if(rlist.selectedIndex < 0 || rlist.selectedIndex > rlist.options.length)return; var i; llist.options.length++; llist.options[llist.options.length-1].value = rlist.options[rlist.selectedIndex].value; llist.options[llist.options.length-1].text = rlist.options[rlist.selectedIndex].text; for(i = rlist.selectedIndex; i < rlist.options.length - 1; i ++) { rlist.options[i].value = rlist.options[i+1].value; rlist.options[i].text = rlist.options[i+1].text; } rlist.length --; } //把右辚w中的加入左? function AssignRight_AssignSelected(){ for(var i = rlist.length - 1; i >= 0; i --) { if(rlist.options[i].selected) { llist.options.length++; llist.options[llist.options.length-1].value = rlist.options[i].value; llist.options[llist.options.length-1].text = rlist.options[i].text; for(var j = i; j < rlist.options.length - 1; j ++) { rlist.options[j].value = rlist.options[j+1].value; rlist.options[j].text = rlist.options[j+1].text; } rlist.length --; } } } //把右Ҏ有加入左? function AssignRight_AssignAll(){ for(var i = rlist.length - 1; i >= 0; i --) { llist.options.length++; llist.options[llist.options.length-1].value = rlist.options[i].value; llist.options[llist.options.length-1].text = rlist.options[i].text; for(var j = i; j < rlist.options.length - 1; j ++) { rlist.options[j].value = rlist.options[j+1].value; rlist.options[j].text = rlist.options[j+1].text; } rlist.length --; } } //左边select目双击 function DenyUser() { if(llist.selectedIndex < 0 || llist.selectedIndex > llist.options.length)return; var i; rlist.options.length++; rlist.options[rlist.options.length-1].value = llist.options[llist.selectedIndex].value; rlist.options[rlist.options.length-1].text = llist.options[llist.selectedIndex].text; for(i = llist.selectedIndex; i < llist.options.length - 1; i ++) { llist.options[i].value = llist.options[i+1].value; llist.options[i].text = llist.options[i+1].text; } llist.length --; } //把左辚w中的项目加入右? function AssignRight_DenySelected() { for(var i = llist.length - 1; i >= 0; i --) { if(llist.options[i].selected) { rlist.options.length++; rlist.options[rlist.options.length-1].value = llist.options[i].value; rlist.options[rlist.options.length-1].text = llist.options[i].text; for(j = llist.selectedIndex; j < llist.options.length - 1; j ++) { llist.options[j].value = llist.options[j+1].value; llist.options[j].text = llist.options[j+1].text; } llist.length --; } } } //左边所有项目加入右? function AssignRight_DenyAll() { for(var i = llist.length - 1; i >= 0; i --) { rlist.options.length++; rlist.options[rlist.options.length-1].value = llist.options[i].value; rlist.options[rlist.options.length-1].text = llist.options[i].text; for(j = i; j < llist.options.length - 1; j ++) { llist.options[j].value = llist.options[j+1].value; llist.options[j].text = llist.options[j+1].text; } llist.length --; } }
]]>[转] JSP 中生成WORD文档 http://www.aygfsteel.com/Michael-Q/articles/133466.htmlQBing_M QBing_M Mon, 30 Jul 2007 17:00:00 GMT http://www.aygfsteel.com/Michael-Q/articles/133466.html http://www.aygfsteel.com/Michael-Q/comments/133466.html http://www.aygfsteel.com/Michael-Q/articles/133466.html#Feedback 0 http://www.aygfsteel.com/Michael-Q/comments/commentRss/133466.html http://www.aygfsteel.com/Michael-Q/services/trackbacks/133466.html 转自Q?a ); //输出word文档 if(blob!=null){ InputStream pi = blob.getBinaryStream(); int blobsize =(int)blob.length(); byte[] blobbytes = new byte[blobsize]; int bytesRead = 0; while ((bytesRead = pi.read(blobbytes)) != -1) { sos.write(blobbytes, 0, bytesRead); } pi.close(); sos.flush(); sos.close(); } getBlob.dropConnFunction(); }catch(Exception e){ System.out.println(e.toString()); } } //Clean up resources public void destroy() { } }
]]> [转]hibernate存取囄CZ http://www.aygfsteel.com/Michael-Q/articles/133465.htmlQBing_M QBing_M Mon, 30 Jul 2007 16:56:00 GMT http://www.aygfsteel.com/Michael-Q/articles/133465.html http://www.aygfsteel.com/Michael-Q/comments/133465.html http://www.aygfsteel.com/Michael-Q/articles/133465.html#Feedback 0 http://www.aygfsteel.com/Michael-Q/comments/commentRss/133465.html http://www.aygfsteel.com/Michael-Q/services/trackbacks/133465.html 转自 http://blog.csdn.net/jyh_jack/archive/2007/01/22/1490120.aspx 一般网站在处理用户上传囄旉常采用两种{略Q一是直接把囄存入数据库中的Blob字段Q二是数据库中只存储囄的在服务器上的\径信?Q图片存攑֜分门别类的文件中Q用的时候从数据库读取\径信息到面img元素卛_Q在此不讨论两种Ҏ的优劣,我只是写了个hibernate的例子来实现W一U策略.例子很简单,t_user表主要两个字D,name和photoQ其中photo字段cd为BlobQ在此例中数据库我采用mysqlQoracle的Blob字段比较ҎQ你必须自定义类型,具体的请自行搜烦Q这斚w的资料很多. //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; } } cUser有3个属性,id,name,photoQ相应的getter和setterҎ以及一个无参构造函敎ͼ应该注意的是photo的类型java.sql.Blob 相应的user.hbm.xml应该如下Q?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> 对应的hibernate.cfg.xml配置文gQ不再列出,请参照hibernate文档自行讑֮Q?br> QOQ做了这一步,我们写个试cLq行单元试Q?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(); } } } 我们dC盘目录下的test.gifq存储到数据库中Q然后再取出来写入C:\out目录Q此时你可以查看下数据表中photo昄为blob,表示已经成功存入Q值的注意的代码片D就是: FileInputStream in=new FileInputStream("C:\\test.gif"); Blob photo=Hibernate.createBlob(in); 我们q里是从盘中读取图片,实际应用中你可以利用上传lg得到囄的2q制数据,q利用Hibernate.createBlobҎ来构造相应的Blob对象Q而取囄则?br> InputStream in=photo.getBinaryStream(); q只是个单的试c,如果我想从数据库中取出图片ƈ现实在页面上该如何做呢?其实也很单,我们先要写一个servletQ在它的serviceҎ中取出图片,qӞ画"到指定页面上Q?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取得输出,其他׃上段代码一_servlet写好了,怎么在页面调用呢Q那更单啦Q直接在面的img标签的src属性上调用该servlet卛_Q如Q?br> <img id="test" src="/servlet/Test"/>
]]> [转]l于搞定关于Hibernte的Blob更新操作 http://www.aygfsteel.com/Michael-Q/articles/133463.htmlQBing_M QBing_M Mon, 30 Jul 2007 16:51:00 GMT http://www.aygfsteel.com/Michael-Q/articles/133463.html http://www.aygfsteel.com/Michael-Q/comments/133463.html http://www.aygfsteel.com/Michael-Q/articles/133463.html#Feedback 0 http://www.aygfsteel.com/Michael-Q/comments/commentRss/133463.html http://www.aygfsteel.com/Michael-Q/services/trackbacks/133463.html 阅读全文 ]]> hibernate 保存大字D|据到数据?sqlserver) http://www.aygfsteel.com/Michael-Q/articles/hibernate.htmlQBing_M QBing_M Mon, 30 Jul 2007 16:34:00 GMT http://www.aygfsteel.com/Michael-Q/articles/hibernate.html http://www.aygfsteel.com/Michael-Q/comments/133462.html http://www.aygfsteel.com/Michael-Q/articles/hibernate.html#Feedback 0 http://www.aygfsteel.com/Michael-Q/comments/commentRss/133462.html http://www.aygfsteel.com/Michael-Q/services/trackbacks/133462.html q期 需要操作hibernate把图片往sql 2005里添加,先搜集下资料?br>以下载自http://blog.csdn.net/haofeng82/archive/2007/06/30/1672299.aspx 在此感谢 q里是以sqlserverZ子的 Qoracle的特D性暂不考虑?/p>
我感觉大字段的保存应该有如下几步Q?/p>
1 首先你必dC个代表上传文件的数据;
2 需要一张表存储大字D|据:包括内容Q类?mimetype)Q这p看你d时如何操作文件了Q?/p>
如果你想~存到硬盘上的话可能需要一个文件\径字D,{等?/p>
3 q行保存操作
假设你已l能够获得文件流对象了应该是一个inputstreamQ我们可以编写下面的代码保存数据到数据库Q?/p>
tran = session.beginTransaction(); TblEAccessory test=new TblEAccessory(); test.setId("testId"); test.setFileCacheName(ufile.getBaseFileName()); test.setFileExt(ufile.getExt());
//q里没有讄mimetype,应该讄?/p>
Blob b = Hibernate.createBlob(ufile.fileItem.getInputStream()); test.setFileContent(b); session.save(test); tran.commit();
q里的ufile对象是封装了fileupload的fileItem的一个类的实例,主要是存储了上传文g的流。最关键的是
ufile.fileItem.getInputStream()Q得C文g的流对象Q怎么得到q不是这里需要讨论的问题?/p>
然后我们创徏了一个hibernate 大字D,D|上p了?/p>
--Z么没使用oracle作例子,因ؓ好风最q做的项目老是使用sqlserverQ再加上听说oracle的最新驱动已l解决了hibernate大字D늚Ҏ操作Q还没试q,看看?/p>
--使用hibernateq行大字D|作还可以通过自定义类型实玎ͼ公司里用的就是这个,不过我懒Q还是喜Ƣ这U方?/p>
]]>
վ֩ģ壺
³ɽ |
п |
|
Դ |
ˮ |
ҵ |
|
|
|
|
ȷ |
ɽ |
ˮ |
|
|
|
ʡ |
֣ |
ƽ |
п |
¡ |
ڰ |
|
|
â |
|
|
ͩ |
|
ض |
|
ϳ |
|
ͨ |
ƽ |
Դ |
¬ |
|
ɽ |
̨ |
鶴 |