如何从数据库中读出文件并作为附件用JAVA MAIL发送出去?
文件以BLOB的方式存在数据库中,
要求读出文件并作为附件用JAVA MAIL发送出去?
求助高手给出范例代吗?谢谢!
问题点数:20、回复次数:2Top
1 楼k3179(螃蟹)回复于 2006-03-14 17:02:33 得分 20
ResultSet rs;
String filename; //文件名
javax.activation.FileDataSource(rs.getBlob(filename).getBinaryStream())Top
2 楼harrylu(Harry)回复于 2006-03-17 16:16:52 得分 0
AttachmentMode oAttachmentMode= oAttachmentAdapter.getAttachment(attachmentId); //read the pic from DB and store into a data model.
byte[] content = oAttachmentMode.getAttachContent();
DataSource ds = new ByteArrayDataSource(content, "application/x-any", "application/x-any");
DataHandler dataHandler = new DataHandler(ds);
MimeBodyPart attachPIC = new MimeBodyPart();
attachPIC.setDataHandler(dataHandler);
attachPIC.setFileName(oAttachmentMode.getFileName());
...
Top




