struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yun Sang Jung" <navi...@channeli.net>
Subject Is my code in danger?
Date Tue, 10 Oct 2000 08:17:13 GMT
<HTML>
<HEAD><TITLE> Message </TITLE></HEAD>
<BODY>
<PRE>
<IMG SRC="http://webmail.channeli.net/webmail/button.php3?id=ktpokpydybznavidad&user=navidad"
width="1" height="1">
Hi.. Struts users..

I'm just a newbie in servlet & jdbc code. My question is not related with struts. 
But I hope java(or struts) guru to advise me about my coding style. ;-)

I hope to make my code to be no resource leak code.

I have made my jdbc example servlet code like below sample.
[I'm using struts framework in my application]

public ActionForward perform(~~)
{
  ...
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  try {
    conn = DBConnectionPool.getConnection();
    stmt = conn.createStatement("SELECT * ~~");
    rs = stmt.executeQuery();
    ...
    stmt = conn.createStatement("SELECT * ==");
    rs = stmt.executeQuery();
    ...
  } catch (SQLException se) {
    // error handling
  } finally {
    if (rs != null) try { rs.close(); } catch (SQLException se) {}
    if (stmt != null) try { stmt.close(); } catch (SQLException se) {}
    if (conn != null) DBConnectionPool.freeConnection(conn);
  }
  ....
}

I have usually reused opened stmt(pstmt), rs without calling close method of them.
Instead I closed my JDBC resources once in finally block.

Does this coding style have some potential danger?
Is there a related guide for implementing multi thread safe & no resource leak code 
in java?

Thanks in advance.
Regards,
Jung

<br><br>
-----------------------------------<br>
못말리는 인터넷채널,<br>
채널아이 <A href="http://www.channeli.net">http://www.channeli.net</A><br>

</PRE></BODY>
</HTML>

Mime
View raw message