ps = conn.prepareStatement(str2)前,ps是否一定要close??????

ragweed_wg 2003-06-27 06:14:24
public int create(AttachmentValue detail) throws InfoDAOException
{
Connection conn = null;
PreparedStatement ps = null;
int rownum = 0;

String str = "insert into attachment (id, infoid, attachment, ext, " +
"filename, attachmentsize, description) values (seq_attachment.nextval, ?, ?, ?, ?, ?, ?)";

String str2 = "select seq_attachment.currval from dual";

String str3 = "select attachment from attachment where id = ? for update";

try
{
//conn = getConnection();
conn = getWriteConnection();
try
{
conn.setAutoCommit(false);
}
catch (Exception e)
{
}

boolean attachment_flag = true;
ps = conn.prepareStatement(str);
ps.setInt(1, detail.getInfoid());
if (detail.getAttachment() != null)
{
//ps.setBytes(2, detail.getAttachment());
//ByteArrayInputStream stream = new ByteArrayInputStream (detail.getAttachment());
//ps.setBinaryStream(2,stream,detail.getAttachment().length);
ps.setBytes(2, " ".getBytes());
}
else
{
ps.setBytes(2, " ".getBytes());
attachment_flag = false;
}
if (detail.getExt() != null)
{
ps.setString(3, detail.getExt());
}
else
{
ps.setNull(3, java.sql.Types.VARCHAR);
}
ps.setString(4, detail.getFilename());
if (attachment_flag)
{
ps.setInt(5, detail.getAttachment().length);
}
else
{
ps.setInt(5, 0);
}
if (detail.getDescription() != null)
{
ps.setString(6, detail.getDescription());
}
else
{
ps.setNull(6, java.sql.Types.VARCHAR);
}
rownum = ps.executeUpdate();

//**************************************************
ps.close(); //是否必须????
//**************************************************


ps = conn.prepareStatement(str2);
ResultSet rs = ps.executeQuery();

if(rs.next())
{
rownum = rs.getInt(1);
}
//**************************************************
ps.close() ; //是否必须????
//**************************************************
rs.close();

if ( attachment_flag )
{
ps = conn.prepareStatement(str3);
ps.setInt(1, rownum);
rs = ps.executeQuery();
if( rs.next())
{
java.io.OutputStream os = null;
if (appserver == 0)
{
java.sql.Blob myBlob = null;
myBlob = rs.getBlob(1);
os = ((weblogic.jdbc.common.OracleBlob) myBlob).getBinaryOutputStream();
}
else if (appserver >= 1)
{
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob(1);
os = blob.getBinaryOutputStream();
}
os.write(detail.getAttachment());
os.flush();
os.close();
}
//**************************************************
ps.close() ; //是否必须????
//**************************************************
rs.close();
}

ps.close();
try
{
conn.commit();
}
catch (Exception e)
{
}
detail.setId(rownum);
if( attachment_flag )
{
detail.setAttachmentsize(detail.getAttachment().length);
}
else
{
detail.setAttachmentsize(0);
}
}
catch (Exception e)
{
try
{
conn.rollback();
}
catch(Exception ex)
{
}
//e.printStackTrace();
throw new InfoDAOException("劤藤Attachment斤口珂??! " + e.toString());
}
finally
{
ps = null;
try
{
conn.setAutoCommit(true);
}
catch(Exception e)
{
}
try
{
conn.close();
}
catch (Exception e)
{
}
conn = null;
}
return rownum;
}
...全文
155 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjsyjs 2003-06-27
  • 打赏
  • 举报
回复
close
zhaoxichao 2003-06-27
  • 打赏
  • 举报
回复
应该关闭
不过如果没有关闭,在连接关闭以后,这个内存也同时被释放了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧