mysql存储word文档_使用MySQL存储和检索word文档
我需要使用Servlet將MS Word文檔存儲和檢索到MySQL 5.1中。我有上傳文件的代碼,但我不知道我可以加入表格。我已經在我要插入.doc文件的字段中使用了BLOB。
這是我上傳文件的代碼片段:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// get access to file that is uploaded from client
Part p1 = request.getPart("file");
String type=p1.getContentType();
String name=p1.getName();
long size = p1.getSize();
InputStream is = p1.getInputStream();
//FileInputStream fis = is.
// read filename which is sent as a part
Part p2 = request.getPart("name");
Scanner s = new Scanner(p2.getInputStream());
String filename = s.nextLine(); // read filename from stream
// get filename to use on the server
String outputfile = this.getServletContext().getRealPath(filename); // get path on the server
FileOutputStream os = new FileOutputStream (outputfile);
// write bytes taken from uploaded file to target file
int ch = is.read();
while (ch != -1) {
os.write(ch);
ch = is.read();
}
os.close();
out.println("
File : '" + name + "' Type : '" + type + "' "
+ "of Size : " + ((double) size/1024) + "KB uploaded successfully!");
}
catch(Exception ex) {
out.println("Exception -->" + ex.getMessage());
}
finally {
out.close();
}
}
在這里,我使用Servlets 3.0功能上傳文件...
我的表架構:
resources
- UserID [varchar(15)]
- Document [mediumblob]
任何人都可以幫助我如何將文檔存儲到表中,雖然BLOB是一種表示二進制數據的類型,但我如何檢索為Word文檔(* .doc)?
總結
以上是生活随笔為你收集整理的mysql存储word文档_使用MySQL存储和检索word文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 未能加载文件或程序集rsy3_abp v
- 下一篇: mysql使字段自增_Mysql设置自增