how to replace ? using regular expression

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]

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