struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yun Sang Jung" <>
Subject Is my code in danger?
Date Tue, 10 Oct 2000 08:17:13 GMT
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.

못말리는 인터넷채널,<br>
채널아이 <A href=""></A><br>


View raw message