public String toString(){
  StringBuffer result=new StringBuffer();
  boolean isEscaped=false;
  boolean isString=false;
  int parameterIndex=0;
  for (int i=0; i < m_sql.length(); i++) {
    char charValue=m_sql.charAt(i);
switch (charValue) {
case '\\':
      isEscaped=!isEscaped;
    result.append(charValue);
  break;
case '\'':
if (!isEscaped) isString=!isString;
result.append(charValue);
isEscaped=false;
break;
case '?':
if (!isEscaped && !isString) {
parameterIndex++;
if (m_variables.containsKey(parameterIndex)) {
result.append(m_variables.get(parameterIndex));
}
 else {
result.append(charValue);
}
}
 else {
result.append(charValue);
isEscaped=false;
}
break;
default :
result.append(charValue);
isEscaped=false;
break;
}
}
return result.toString();
}

public String toString ( ) { StringBuffer result = new StringBuffer ( ) ; boolean isEscaped = false ; boolean isString = false ; int parameterIndex = 0 ; for ( int i = 0 ; i < m_sql . length ( ) ; i ++ ) { char charValue = m_sql . charAt ( i ) ; switch ( charValue ) { case '\\' : isEscaped = ! isEscaped ; result . append ( charValue ) ; break ; case '\'' : if ( ! isEscaped ) isString = ! isString ; result . append ( charValue ) ; isEscaped = false ; break ; case '?' : if ( ! isEscaped && ! isString ) { parameterIndex ++ ; if ( m_variables . containsKey ( parameterIndex ) ) { result . append ( m_variables . get ( parameterIndex ) ) ; } else { result . append ( charValue ) ; } } else { result . append ( charValue ) ; isEscaped = false ; } break ; default : result . append ( charValue ) ; isEscaped = false ; break ; } } return result . toString ( ) ; }
string representation of the sql statement in the database . < p > some jdbc drivers do not return a readable sql statement but only an object reference when the tostring ( ) method is called on a prepared statement . < p > this wrapper replaces the parameters in the prepared statement with the actual values which were set to produce human readable output in the log . < p > note that the resulting sql string may still not be executable in the target database , as java ' s tostring ( ) method is used to represent each object in the sql string , disregarding syntax conventions required by the database .
