日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql存储word文档_使用MySQL存储和检索word文档

發布時間:2024/1/23 数据库 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。