Q
qcchan
Unregistered / Unconfirmed
GUEST, unregistred user!
分两步
第一步,把文件转换到BYTE数组,保存到数据库
这儿是DELPHI7的代码,转换成的数组再转换成文件也没有问题
procedure TFrmMAIN.Button2Click(Sender: TObject);
var sm:TMemorystream;
byt:ArrayOfbyte;//ArrayOfbyte = array of of byte; 这是用WSDL转换得到的,
icount:integer;
main_Service:MainService;
begin
main_Service:=getMainService;
sm := TMemorystream.Create;
sm.LoadFromFile('./chimes.wav');
iCount := sm.size;
setlength(byt,iCount);
sm.Read(byt[0],iCount);
main_Service.saveBinaryFile('171',byt);
end;
这是JAVA写的 webservice的存储BTYE叔祖的代码,后台数据库书SQL2000
public boolean saveBinaryFile(String acct_id, byte[] image) {
FUserImage userImage = new FUserImage();
Session s = null;
boolean rs = false;
Transaction tx = null;
try {
s = HibernateUtil.currentSession();
tx = s.beginTransaction();
userImage.setAcctId(acct_id);
userImage.setFilesize(new Integer(image.length));
System.out.print("================================1"+image.length) ;
userImage.setFilebin(image);
System.out.print("================================2"+image) ;
s.save(userImage);
tx.commit();
HibernateUtil.closeSession();
rs = true;
}
catch (HibernateException ex) {
rs = false;
}
return rs;
}
第2步,从数据库里取回BYTE数组,转换成文件
从webservice 返回一个BYTE数组速度特别慢,我一次都没下载下了
com.thtf.ezone.ezhms.reservation.tables.FUserImage@f77511
下面是webservice 的一段代码
public FUserImage getUserImage(String agr) {
Session s = null;
FUserImage rt = null;//这个对象包含了帐号、文件长度和一个BYTE数组
try {
s = HibernateUtil.currentSession();
Query q = s.createQuery(agr);
List rs = q.list();
if (rs.size() > 0) {
rt = (FUserImage) rs.get(0);
System.out.print(rt)
//这个是打印到TOMCAT的内容表示webservice已经得到了一个对象
;com.thtf.ezone.ezhms.reservation.tables.FUserImage@f77511
}
HibernateUtil.closeSession();
}
catch (HibernateException ex) {
return null;
}
return rt;
}
下面是DELPHI7的一段代码
function getBinaryFile(acct_id:String):boolean;
var
sm:TMemorystream;
byt:ArrayOfbyte;
icount:integer;
main_Service:MainService;
userImage:FUserImage ;
begin
main_Service:=getMainService;
userImage:=FUserImage.Create ;
userImage:=main_Service.getUserImage('from FUserImage where acct_id='''+acct_id+'''');
//在这儿就停止不动了,我等了一小时,但是程序没有死,这是为什么呢?
setlength(byt,userImage.filesize);
byt:=userImage.filebin ;
iCount := sizeof(byt);
sm := TMemorystream.Create;
sm.SetSize(iCount);
sm.Write(byt[0],icount);
sm.SaveToFile('./bbb123.bmp');
end;
第一步,把文件转换到BYTE数组,保存到数据库
这儿是DELPHI7的代码,转换成的数组再转换成文件也没有问题
procedure TFrmMAIN.Button2Click(Sender: TObject);
var sm:TMemorystream;
byt:ArrayOfbyte;//ArrayOfbyte = array of of byte; 这是用WSDL转换得到的,
icount:integer;
main_Service:MainService;
begin
main_Service:=getMainService;
sm := TMemorystream.Create;
sm.LoadFromFile('./chimes.wav');
iCount := sm.size;
setlength(byt,iCount);
sm.Read(byt[0],iCount);
main_Service.saveBinaryFile('171',byt);
end;
这是JAVA写的 webservice的存储BTYE叔祖的代码,后台数据库书SQL2000
public boolean saveBinaryFile(String acct_id, byte[] image) {
FUserImage userImage = new FUserImage();
Session s = null;
boolean rs = false;
Transaction tx = null;
try {
s = HibernateUtil.currentSession();
tx = s.beginTransaction();
userImage.setAcctId(acct_id);
userImage.setFilesize(new Integer(image.length));
System.out.print("================================1"+image.length) ;
userImage.setFilebin(image);
System.out.print("================================2"+image) ;
s.save(userImage);
tx.commit();
HibernateUtil.closeSession();
rs = true;
}
catch (HibernateException ex) {
rs = false;
}
return rs;
}
第2步,从数据库里取回BYTE数组,转换成文件
从webservice 返回一个BYTE数组速度特别慢,我一次都没下载下了
com.thtf.ezone.ezhms.reservation.tables.FUserImage@f77511
下面是webservice 的一段代码
public FUserImage getUserImage(String agr) {
Session s = null;
FUserImage rt = null;//这个对象包含了帐号、文件长度和一个BYTE数组
try {
s = HibernateUtil.currentSession();
Query q = s.createQuery(agr);
List rs = q.list();
if (rs.size() > 0) {
rt = (FUserImage) rs.get(0);
System.out.print(rt)
//这个是打印到TOMCAT的内容表示webservice已经得到了一个对象
;com.thtf.ezone.ezhms.reservation.tables.FUserImage@f77511
}
HibernateUtil.closeSession();
}
catch (HibernateException ex) {
return null;
}
return rt;
}
下面是DELPHI7的一段代码
function getBinaryFile(acct_id:String):boolean;
var
sm:TMemorystream;
byt:ArrayOfbyte;
icount:integer;
main_Service:MainService;
userImage:FUserImage ;
begin
main_Service:=getMainService;
userImage:=FUserImage.Create ;
userImage:=main_Service.getUserImage('from FUserImage where acct_id='''+acct_id+'''');
//在这儿就停止不动了,我等了一小时,但是程序没有死,这是为什么呢?
setlength(byt,userImage.filesize);
byt:=userImage.filebin ;
iCount := sizeof(byt);
sm := TMemorystream.Create;
sm.SetSize(iCount);
sm.Write(byt[0],icount);
sm.SaveToFile('./bbb123.bmp');
end;