Menu

rs.getString with trim

Help
tcy
2005-07-17
2013-04-25
  • tcy

    tcy - 2005-07-17

    Not sure if this will be useful to others but I was looking around the whole day why there is no match between the username. Turns out firebird doesn't return string that is trim when calling rs.getString

    //previously
    pObject.setUserName(rs.getString(3));
    //after edit will generate the following
    pObject.setUserName((rs.getString(3)).trim());

    xManagerTemplate.vm
    -----------------
    //72
    public $beanClass decodeRow(ResultSet rs) throws SQLException
    {....

    //        pObject.$strUtil.getSetMethod($column)($column.getResultSetMethodObject($vCount));
    #if ($column.getResultSetMethodObject($vCount) == "rs.getString($vCount)")
            pObject.$strUtil.getSetMethod($column)(($column.getResultSetMethodObject($vCount)).trim());
        #else
            pObject.$strUtil.getSetMethod($column)($column.getResultSetMethodObject($vCount));
        #end

    ....}

     
    • nr

      nr - 2005-07-17

      Hi,

      Thanks, it might help others. Note that we do not prefer to trim the string at this level, inserting space might be done on purpose: (in password etc...).

      Be careful, your patch is dangerous as getString could return null => nullpointerexception.

      N.

       
      • tcy

        tcy - 2005-07-18

        Thanks, noted that the "standard" way of sql2java will not trim at this level
        will revert to calling trim when accessing each string field

        Is there be a common way of sorting eg. when using loadAll?

        a update(included check for null) for those who are still interested in deviatating from the common way of sql2java
        ---------
            //72
            public $beanClass decodeRow(ResultSet rs) throws SQLException
            {
                $beanClass pObject = create$beanClass();
                String tmpStr;
        ## the set statement casts $velocityCount to a string
        #foreach ( $column in $columns )
        #set ($vCount = "$velocityCount" )
                //pObject.$strUtil.getSetMethod($column)($column.getResultSetMethodObject($vCount));
            #if ($column.getResultSetMethodObject($vCount) == "rs.getString($vCount)")
                 tmpStr = $column.getResultSetMethodObject($vCount);
                if (tmpStr != null)
                    pObject.$strUtil.getSetMethod($column)(tmpStr.trim());
                else
                    pObject.$strUtil.getSetMethod($column)(tmpStr);        
            #else
                pObject.$strUtil.getSetMethod($column)($column.getResultSetMethodObject($vCount));
            #end
        #end

                pObject.isNew(false);
                pObject.resetIsModified();

                return pObject;
            }

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.