java - Preventing Prepared Statement Leaks using Checkstyles -
lets have following code :
preparedstatement ps = null; resultset rs = null; try { ps = conn.createstatement(myquerystring); rs = ps.executequery(); // process results... } catch (java.sql.sqlexception e) { log.error("an error!", e); throw new exception("i'm sorry. query did not work."); } { ps.close(); // if forgot leak rs.close(); // if forgot leak }
and wished catch scenario forget close preparedstatement
or resultset
using checkstyles. possible, , if so, how go it?
pmd , findbugs both have warnings preparedstatements (and resultsets , connections). i'd suggest using them type of warning, since checkstyle has more code style finding data-flow bugs such this.
Comments
Post a Comment