/**
* 普通附件上傳
* @param uploads
* @param uploadFileNames
* @param uploadFileLabs
* @param apply_id_fname
* @param attach_id_fname
* @param attach_name_fname
* @param attach_fname
* @param attach_lab_fname
* @param tname
* @param apply_id
*
@return
*
@throws Exception */ public boolean insermultipleFileDisk(List<File> uploads, List<String> uploadFileNames, List<String> uploadFileLabs, String apply_id_fname, String attach_id_fname, String attach_name_fname, String attach_fname, String attach_lab_fname, String tname, String apply_id) throws Exception { StringBuffer insert_sql = new StringBuffer(); insert_sql.append("insert into "); insert_sql.append(tname); insert_sql.append("("); insert_sql.append(attach_id_fname).append(","); insert_sql.append(apply_id_fname).append(","); insert_sql.append(attach_name_fname).append(","); insert_sql.append(attach_fname).append(","); insert_sql.append(attach_lab_fname); insert_sql.append(") values "); insert_sql.append(" (?,?,?,?,?) "); String delte_sql = "delete " + tname + " where " + apply_id_fname + "=? and trim(" + attach_lab_fname + ")=?"; Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; String attach_id = ""; try { log.debug(insert_sql.toString()); conn = jt.getDataSource().getConnection(); conn.setAutoCommit(false); for (int i = 0; i < uploads.size(); i++) { String serverDir = ConfigAttach.getAttachDir(); if (StringUtils.endsWith(serverDir, "/")) { serverDir = StringUtils.removeEndIgnoreCase(serverDir, "/"); } String formater = "yyyy/MM/dd"; String serverPath = "/datafiles/" + DateHelper.formatDate2String(new Date(), formater) + "/";// 構建圖片保存的目錄 String fileType = uploadFileNames.get(i) .substring(uploadFileNames.get(i).lastIndexOf('.') + 1) .toLowerCase(); // 獲取文件的名稱,採用UUID的方式 String fileName = UUID.randomUUID().toString() + "." + fileType; // 獲取完成路徑 String filepath = serverPath + fileName; File descFile = new File(serverDir + filepath); // 若是目錄不存在就建立 if (!descFile.exists()) { descFile.getParentFile().mkdirs(); } log.debug("upload attach path:" + descFile.getAbsolutePath()); FileUtils.copyFile(uploads.get(i), descFile); String strFileName=uploadFileNames.get(i); ps = conn.prepareStatement(delte_sql); ps.setString(1, apply_id); ps.setString(2, uploadFileLabs.get(i).trim()); ps.executeUpdate(); attach_id = queryGuidFromOracle(); ps = conn.prepareStatement(insert_sql.toString()); ps.setString(1, attach_id);//附件的主鍵 ps.setString(2, apply_id);//附件的依據主鍵,即誰傳的附件 ps.setString(3, strFileName);//附件的真實文件名 ps.setString(4, filepath);//文件的下載地址 ps.setString(5, uploadFileLabs.get(i).trim()); ps.executeUpdate(); } conn.commit(); conn.setAutoCommit(true); close(conn, ps, rs); } catch (SQLException e) { e.printStackTrace(); try { conn.rollback(); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return false; } return true; } }