IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

how to replace ? using regular expression

  • 1.  how to replace ? using regular expression

    Posted Fri October 01, 2004 08:16 PM

    loop thru valueList

    inString
    SELECT DISTINCT R.AUTHORIZATION FROM TABLE R
    WHERE R.NAME = ?
    AND R.KEY = ?
    AND UPPER(TRIM(R.CITY)) = ?
    AND UPPER(TRIM(R.STATE)) = ?

    searchString (first instance of ?)
    ?

    replaceString
    valueList[i]


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods


  • 2.  RE: how to replace ? using regular expression

    Posted Tue October 05, 2004 12:59 AM

    why the need for regular expressions? I’d just write a little bit of java code to do it (see below)…

    But: you are doing what the adapter services for the JDBC adapter already do, and you could potentially open yourself up to the old “hack/break the sql” problem when someone passes in some characters that interfere with the query. That’s why everyone uses PreparedStatements rather than building the SQL themselves these days. If someone passes in some SQL syntax, or a few quotes or semicolon: your query will be broken.

    But, since you may have a need to (although I’d recommend against putting unescaped strings in):

    Inputs:
    inputString
    valueList

    Outputs:
    outputString

    --------Begin service code

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    String	inputString = IDataUtil.getString( pipelineCursor, "inputString" );
    String[]	valueList = IDataUtil.getStringArray( pipelineCursor, "valueList" );
    
    pipelineCursor.destroy();
    
    
    StringTokenizer tokens = new StringTokenizer(inputString, "?", true);
    
    StringBuffer stringBuff = new StringBuffer();
    
    int i=0;
    
    while(tokens.hasMoreTokens())
    {
    String currentToken = tokens.nextToken();
    if (currentToken.equals("?"))
    {
    stringBuff.append(valueList[i]);
    i++;
    }
    else
    {
    stringBuff.append(currentToken);
    }	
    }
    
    
    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();
    IDataUtil.put( pipelineCursor_1, "outputString", stringBuff.toString() );
    pipelineCursor_1.destroy();
    
    

    ----end service code

    PS you’ll need java.util.StringTokenizer in the imports section ofyour java service.

    Regards,
    Nathan Lee


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods