public static void addAttach(String source, String id, String filename, String memo)
{
if ((filename.equals("")) || (filename == null)) {
return;
}
BufferedOutputStream out = null;
InputStream in = null;
int c = 0;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql = null;
BLOB blob2 = null;
OracleResultSet rs2 = null;
try
{
sqlMap = TheAppSqlConfig.getSqlMapInstance();
conn = sqlMap.getDataSource().getConnection();
stmt = conn.createStatement();
conn.setAutoCommit(false);
boolean defaultCommit = conn.getAutoCommit();
String attachid = Sequence.getNextValue("get-nextattachid");
sql = "insert into all_attach(attachid,id,source,name,attach,memo) values(" + attachid + "," + id + ",'" + source + "','" + filename + "',empty_blob(),'" + memo + "')";
stmt.executeUpdate(sql);
sql = "select attach from all_attach where attachid = " + attachid + " for update";
rs = stmt.executeQuery(sql);
String pfile = FILE_PATH + filename;
while (rs.next())
{
blob2 = (BLOB)rs.getBlob(1);
out = new BufferedOutputStream(blob2.getBinaryOutputStream());
in = new FileInputStream(pfile);
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.close();
}
conn.commit();
conn.setAutoCommit(defaultCommit);
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.close();
conn = null;
delFile(filename);
}
catch (Exception ex)
{
try
{
conn.rollback();
conn.close();
}
catch (Exception e)
{
log.info("conn.rollback: " + e.toString());
}
}
finally {
Conc.closeConnection(conn, stmt, rs, true);
}
}
阅读(612) | 评论(0) | 转发(0) |