[英]save multiple attachments in java
我已經將一個文件保存到數據庫中(postgresql),並且工作正常。 但是當我嘗試上傳多個文件時,我陷入了困境。
我的jsp文件上傳:
<input type="file" id="reqFile" name="attachments.myFile" multiple/>
這是我的操作方法:
public String SaveAttachments() throws SQLException, IOException {
int case_id = (Integer) session.get("case_id");
System.out.println("in save attachments()");
int uploaded_by = 1;
try {
File destFile = new File(attachments.getMyFileFileName());
FileUtils.copyFile(attachments.getMyFile(), destFile);
fis = new FileInputStream(destFile);
currentCon = ConnectionManager.getConnection();
pstmt = (PreparedStatement) currentCon.prepareStatement("insert into case_attachments(case_id, attachment, attachment_title, upload_date, uploaded_by) values(?,?,?,current_date,?)");
pstmt.setInt(1, case_id);
pstmt.setBinaryStream(2, fis, (int) destFile.length());
pstmt.setString(3, attachments.getMyFileFileName());
pstmt.setInt(4, uploaded_by);
pstmt.executeUpdate();
} catch (Exception e) {
System.out.println("Error From SaveAttachments :" + e);
}
return SUCCESS;
}
當我附加多個文件時,它將以逗號分隔的格式進入數據庫的同一列。 用戶附加多個文件時,如何保存文件在不同的行中? 提前致謝。
使用數組進行多次上傳。
<td><input type="file" name="file[]" class="multi" id="reqFile"></td>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.