Commit 115862fe authored by 王炜's avatar 王炜

调整产品excel导入并保存文件可能出现流未正常关闭,内存泄露问题

parent 641c6a94
......@@ -147,44 +147,53 @@ public class ImportExcel extends AbstractEntry {
throw new IllegalArgumentException();
}
FileOutputStream fout = new FileOutputStream(savePath);
byte[] buffer = new byte[1024];
int len = 0;
int size = 0;
while((len = in.read(buffer)) > 0 ){
fout.write(buffer, 0, len);
size += len;
try {
byte[] buffer = new byte[1024];
int len = 0;
int size = 0;
while ((len = in.read(buffer)) > 0) {
fout.write(buffer, 0, len);
size += len;
}
fout.flush();
fout.close();
in.close();
// 保存记录到数据库
//fnd_atm_attachment
String sql = "{call fnd_atm_attachment_pkg.insert_fnd_atm_attachment(?,?,?,?,?,?,?,?,?) }";
CallableStatement cstm = conn.prepareCall(sql);
cstm.registerOutParameter(1, java.sql.Types.NUMERIC);
cstm.setString(2, "fnd_atm_attachment_multi"); // v_source_type_code
cstm.setString(3, "123"); // v_source_pk_value
cstm.setString(4, fileTypeCode); // v_file_type_code
cstm.setString(5, "application/vnd.ms-excel"); // v_mime_type
cstm.setString(6, fileName); // v_file_name
cstm.setLong(7, size); // v_file_size
cstm.setString(8, savePath); // v_file_path
cstm.setLong(9, Long.valueOf(user_id)); // v_user_id
cstm.execute();
Long aid = cstm.getLong(1);
cstm.close();
//fnd_atm_attachment_multi
sql = "{call fnd_atm_attachment_all_pkg.insert_fnd_attachment_multi(?,?,?,?)}";
cstm = conn.prepareCall(sql);
cstm.setString(1, tableName);// tableName
cstm.setString(2, tablePkValue);// tablePkValue
cstm.setLong(3, aid);// attachment_id
cstm.setLong(4, Long.valueOf(user_id));// user_id
cstm.execute();
cstm.close();
}finally{
if(fout!=null){
fout.close();
}
if(in!=null){
in.close();
}
}
fout.flush();
fout.close();
in.close();
// 保存记录到数据库
//fnd_atm_attachment
String sql = "{call fnd_atm_attachment_pkg.insert_fnd_atm_attachment(?,?,?,?,?,?,?,?,?) }";
CallableStatement cstm = conn.prepareCall(sql);
cstm.registerOutParameter(1, java.sql.Types.NUMERIC);
cstm.setString(2, "fnd_atm_attachment_multi"); // v_source_type_code
cstm.setString(3, "123"); // v_source_pk_value
cstm.setString(4, fileTypeCode); // v_file_type_code
cstm.setString(5, "application/vnd.ms-excel"); // v_mime_type
cstm.setString(6, fileName); // v_file_name
cstm.setLong(7, size); // v_file_size
cstm.setString(8, savePath); // v_file_path
cstm.setLong(9, Long.valueOf(user_id)); // v_user_id
cstm.execute();
Long aid = cstm.getLong(1);
cstm.close();
//fnd_atm_attachment_multi
sql = "{call fnd_atm_attachment_all_pkg.insert_fnd_attachment_multi(?,?,?,?)}";
cstm = conn.prepareCall(sql);
cstm.setString(1, tableName);// tableName
cstm.setString(2, tablePkValue);// tablePkValue
cstm.setLong(3, aid);// attachment_id
cstm.setLong(4, Long.valueOf(user_id));// user_id
cstm.execute();
cstm.close();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment