ER-208 SQL Resource Management - Create Statement Within a Loop: Never create Statements inside loops. This rule is only applicable in a connection-pooled environment.

Severity1
Enabledyes
Waivable
Violation
Connection lcon_dbConnection = getConnection();
ResultSet rs = null;
int i = 0;
while ( i< 10 ){
    Statement lst_stmt = lcon_dbConnection.createStatement();
    lst_stmt.executeUpdate(sqlString);
    i++;
};

for (int j=0; j<10; j++){
    Statement sss_stmt = lcon_dbConnection.createStatement();
    lst_stmt.executeUpdate(sqlString);
}

do{
    Statement sss_stmt = lcon_dbConnection.createStatement();
    lst_stmt.executeUpdate(sqlString);
}while (10< i);
Fix
Connection lcon_dbConnection = getConnection();
		        
Statement lst_stmt = lcon_dbConnection.createStatement();
ResultSet rs = null;
int i = 0;
while ( i< 10 ){
    lst_stmt.executeUpdate(sqlString);
    i++;
};

for (int j=0; j<10; j++){
    lst_stmt.executeUpdate(sqlString);
}

do{
    lst_stmt.executeUpdate(sqlString);
}while (10< i);


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