ER-206 Wrong declaration of SQL Resources Management: Do not declare Statements and ResultSets on Instance Level but use local variables on method level only. You may run in leakage problems if you do not close these resources in a connection-pooled environment.

Severity2
Enabledyes
Waivable
Violation
public class MyDao {
Statement global_stmt = null;
ResultSet rs = null;
public void select(){
	Connection lcon_dbConnection = getConnection();
	int i = 0;
	try{
	    global_stmt = lcon_dbConnection.createStatement();
	    rs	= global_stmt.executeQuery("SELECT * FROM DUAL" );
	 } catch (Exception ex){
	     ex.printStackTrace();
	 }
}
Fix
public class MyDao {
		        
public void selectWithLocalResources() throws Exception{
    Statement stmt = null;
    ResultSet rs = null;
try{
    Connection lcon_dbConnection = getConnection();
    stmt = lcon_dbConnection.createStatement();
    rs	= global_stmt.executeQuery("SELECT * FROM DUAL" );
 } catch (Exception ex){
     ex.printStackTrace();
 }finally{
	if (stmt != null){
	   stmt.close();
	}
	if (rs != null){
	    rs.close();
	}
 }
}
}


Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.